Skip to content

Commit c4043c1

Browse files
committed
Move write_span_context to sdk.h
1 parent 9207987 commit c4043c1

File tree

3 files changed

+30
-62
lines changed

3 files changed

+30
-62
lines changed

internal/include/sdk.h

+30-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,35 @@ struct {
3030
__uint(max_entries, MAX_CONCURRENT);
3131
} active_spans_by_span_ptr SEC(".maps");
3232

33-
// Function declaration
34-
static __always_inline long write_span_context(void *go_sc, struct span_context *sc);
33+
static __always_inline long write_span_context(void *go_sc, struct span_context *sc) {
34+
if (go_sc == NULL) {
35+
bpf_printk("write_span_context: NULL go_sc");
36+
return -1;
37+
}
38+
39+
void *tid = (void *)(go_sc + span_context_trace_id_pos);
40+
long ret = bpf_probe_write_user(tid, &sc->TraceID, TRACE_ID_SIZE);
41+
if (ret != 0) {
42+
bpf_printk("write_span_context: failed to write trace ID: %ld", ret);
43+
return -2;
44+
}
45+
46+
void *sid = (void *)(go_sc + span_context_span_id_pos);
47+
ret = bpf_probe_write_user(sid, &sc->SpanID, SPAN_ID_SIZE);
48+
if (ret != 0) {
49+
bpf_printk("write_span_context: failed to write span ID: %ld", ret);
50+
return -3;
51+
}
52+
53+
void *flags = (void *)(go_sc + span_context_trace_flags_pos);
54+
ret = bpf_probe_write_user(flags, &sc->TraceFlags, TRACE_FLAGS_SIZE);
55+
if (ret != 0) {
56+
bpf_printk("write_span_context: failed to write trace flags: %ld", ret);
57+
return -4;
58+
}
59+
60+
return 0;
61+
}
62+
3563

3664
#endif // SDK_H

internal/pkg/instrumentation/bpf/go.opentelemetry.io/auto/sdk/bpf/probe.bpf.c

-30
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,6 @@ struct {
2323
__uint(max_entries, 1);
2424
} new_event SEC(".maps");
2525

26-
static __always_inline long write_span_context(void *go_sc, struct span_context *sc) {
27-
if (go_sc == NULL) {
28-
bpf_printk("write_span_context: NULL go_sc");
29-
return -1;
30-
}
31-
32-
void *tid = (void *)(go_sc + span_context_trace_id_pos);
33-
long ret = bpf_probe_write_user(tid, &sc->TraceID, TRACE_ID_SIZE);
34-
if (ret != 0) {
35-
bpf_printk("write_span_context: failed to write trace ID: %ld", ret);
36-
return -2;
37-
}
38-
39-
void *sid = (void *)(go_sc + span_context_span_id_pos);
40-
ret = bpf_probe_write_user(sid, &sc->SpanID, SPAN_ID_SIZE);
41-
if (ret != 0) {
42-
bpf_printk("write_span_context: failed to write span ID: %ld", ret);
43-
return -3;
44-
}
45-
46-
void *flags = (void *)(go_sc + span_context_trace_flags_pos);
47-
ret = bpf_probe_write_user(flags, &sc->TraceFlags, TRACE_FLAGS_SIZE);
48-
if (ret != 0) {
49-
bpf_printk("write_span_context: failed to write trace flags: %ld", ret);
50-
return -4;
51-
}
52-
53-
return 0;
54-
}
55-
5626
// This instrumentation attaches a uprobe to the following function:
5727
// func (t *tracer) start(ctx context.Context, spanPtr *span, parentSpanCtx *trace.SpanContext, sampled *bool, spanCtx *trace.SpanContext) {
5828
// https://github.com/open-telemetry/opentelemetry-go-instrumentation/blob/effdec9ac23e56e9e9655663d386600e62b10871/sdk/trace.go#L56-L66

internal/pkg/instrumentation/bpf/go.opentelemetry.io/otel/trace/bpf/probe.bpf.c

-30
Original file line numberDiff line numberDiff line change
@@ -31,36 +31,6 @@ struct {
3131
__uint(max_entries, 1);
3232
} new_event SEC(".maps");
3333

34-
static __always_inline long write_span_context(void *go_sc, struct span_context *sc) {
35-
if (go_sc == NULL) {
36-
bpf_printk("write_span_context: NULL go_sc");
37-
return -1;
38-
}
39-
40-
void *tid = (void *)(go_sc + span_context_trace_id_pos);
41-
long ret = bpf_probe_write_user(tid, &sc->TraceID, TRACE_ID_SIZE);
42-
if (ret != 0) {
43-
bpf_printk("write_span_context: failed to write trace ID: %ld", ret);
44-
return -2;
45-
}
46-
47-
void *sid = (void *)(go_sc + span_context_span_id_pos);
48-
ret = bpf_probe_write_user(sid, &sc->SpanID, SPAN_ID_SIZE);
49-
if (ret != 0) {
50-
bpf_printk("write_span_context: failed to write span ID: %ld", ret);
51-
return -3;
52-
}
53-
54-
void *flags = (void *)(go_sc + span_context_trace_flags_pos);
55-
ret = bpf_probe_write_user(flags, &sc->TraceFlags, TRACE_FLAGS_SIZE);
56-
if (ret != 0) {
57-
bpf_printk("write_span_context: failed to write trace flags: %ld", ret);
58-
return -4;
59-
}
60-
61-
return 0;
62-
}
63-
6434
// This instrumentation attaches uprobe to the following function:
6535
// func (noopSpan) tracerProvider(autoEnabled *bool) TracerProvider
6636
// https://github.com/open-telemetry/opentelemetry-go/blob/2e8d5a99340b1e11ca6b19bcdfcbfe9cd0c2c385/trace/noop.go#L98C1-L98C65

0 commit comments

Comments
 (0)