Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable auto/sdk in otel global #1405

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ OpenTelemetry Go Automatic Instrumentation adheres to [Semantic Versioning](http
- Support `google.golang.org/grpc` `1.68.2`. ([#1462](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1462))
- Support `google.golang.org/grpc` `1.69.2`. ([#1467](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1467))
- Support `golang.org/x/net` `0.33.0`. ([#1471](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1471))
- Support the full tracing API with the `otelglobal` probe. ([#1405](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1405))

## [v0.19.0-alpha] - 2024-12-05

Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/instrumentation/bpf/database/sql/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func New(logger *slog.Logger, version string) probe.Probe {
Val: shouldIncludeDBStatement(),
},
},
Uprobes: []probe.Uprobe{
Uprobes: []*probe.Uprobe{
{
Sym: "database/sql.(*DB).queryDC",
EntryProbe: "uprobe_queryDC",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func New(logger *slog.Logger, version string) probe.Probe {
Val: structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "ReaderConfig", "GroupID"),
},
},
Uprobes: []probe.Uprobe{
Uprobes: []*probe.Uprobe{
{
Sym: "github.com/segmentio/kafka-go.(*Reader).FetchMessage",
EntryProbe: "uprobe_FetchMessage",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func New(logger *slog.Logger, version string) probe.Probe {
Val: structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "Message", "Time"),
},
},
Uprobes: []probe.Uprobe{
Uprobes: []*probe.Uprobe{
{
Sym: "github.com/segmentio/kafka-go.(*Writer).WriteMessages",
EntryProbe: "uprobe_WriteMessages",
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also add package constraints on the auto sdk probes?

Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func New(logger *slog.Logger) probe.Probe {
),
},
},
Uprobes: []probe.Uprobe{
Uprobes: []*probe.Uprobe{
{
Sym: "go.opentelemetry.io/auto/sdk.(*tracer).start",
EntryProbe: "uprobe_Tracer_start",
Expand All @@ -86,25 +86,25 @@ type converter struct {
logger *slog.Logger
}

func (c *converter) decodeEvent(record perf.Record) (event, error) {
func (c *converter) decodeEvent(record perf.Record) (*event, error) {
reader := bytes.NewReader(record.RawSample)

var e event
err := binary.Read(reader, binary.LittleEndian, &e.Size)
if err != nil {
c.logger.Error("failed to decode size", "error", err)
return event{}, err
return nil, err
}
c.logger.Debug("decoded size", "size", e.Size)

e.SpanData = make([]byte, e.Size)
_, err = reader.Read(e.SpanData)
if err != nil {
c.logger.Error("failed to read span data", "error", err)
return event{}, err
return nil, err
}
c.logger.Debug("decoded span data", "size", e.Size)
return e, nil
return &e, nil
}

func (c *converter) processFn(e *event) ptrace.ScopeSpans {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ char __license[] SEC("license") = "Dual MIT/GPL";
#define MAX_BUCKETS 8
#define MAX_TRACERS 64

// Records state of our write to auto-instrumentation flag.
bool wrote_flag = false;

struct span_description_t {
char buf[MAX_STATUS_DESCRIPTION_LEN];
};
Expand All @@ -42,7 +45,12 @@ typedef struct tracer_id {
char schema_url[MAX_TRACER_SCHEMA_URL_LEN];
} tracer_id_t;

struct control_t {
u32 kind; // Required to be 1.
};

struct otel_span_t {
u32 kind; // Required to be 0.
BASE_SPAN_PROPERTIES
struct span_name_t span_name;
otel_status_t status;
Expand Down Expand Up @@ -388,6 +396,36 @@ static __always_inline long fill_tracer_id(tracer_id_t *tracer_id, go_tracer_ptr
return 0;
}

// This instrumentation attaches uprobe to the following function:
// func (t *tracer) newSpan(ctx context.Context, autoSpan *bool, name string, opts []trace.SpanStartOption) (context.Context, trace.Span) {
// https://github.com/open-telemetry/opentelemetry-go/blob/ac386f383cdfc14f546b4e55e8726a0a45e8a409/internal/global/trace.go#L161
SEC("uprobe/newSpan")
int uprobe_newStart(struct pt_regs *ctx) {
MrAlias marked this conversation as resolved.
Show resolved Hide resolved
if (wrote_flag) {
// Already wrote flag value.
return 0;
}

void *flag_ptr = get_argument(ctx, 4);
if (flag_ptr == NULL) {
bpf_printk("invalid flag_ptr: NULL");
return -1;
}

bool true_value = true;
long res = bpf_probe_write_user(flag_ptr, &true_value, sizeof(bool));
if (res != 0) {
bpf_printk("failed to write bool flag value: %ld", res);
return -2;
}

wrote_flag = true;

// Signal this uprobe should be unloaded.
struct control_t ctrl = {1};
return bpf_perf_event_output(ctx, &events, BPF_F_CURRENT_CPU, (void *)(&ctrl), sizeof(struct control_t));
}

// This instrumentation attaches uprobe to the following function:
// func (t *tracer) Start(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span)
// https://github.com/open-telemetry/opentelemetry-go/blob/98b32a6c3a87fbee5d34c063b9096f416b250897/internal/global/trace.go#L149
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading