Skip to content

Commit c519c21

Browse files
authored
Merge pull request #358 from bobrik/ivan/propagation-args
Add a helper to extract tracing propagation args
2 parents 5cb1bd3 + 78149b7 commit c519c21

File tree

4 files changed

+34
-24
lines changed

4 files changed

+34
-24
lines changed

tracing/demos/args.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package demos
2+
3+
import (
4+
"github.com/cloudflare/ebpf_exporter/v2/util"
5+
"go.opentelemetry.io/otel/trace"
6+
)
7+
8+
// PropagationArgs returns traceID split into two big-endian u64 and a big-endian u64 spanID,
9+
// which is the expected format to pass tracing information into the kernel for later decoding
10+
// as hex decoder on the output side.
11+
func PropagationArgs(span trace.Span) (uint64, uint64, uint64) {
12+
byteOrder := util.GetHostByteOrder()
13+
14+
spanContext := span.SpanContext()
15+
traceID := spanContext.TraceID()
16+
spanID := spanContext.SpanID()
17+
18+
return byteOrder.Uint64(traceID[0:8]), byteOrder.Uint64(traceID[8:16]), byteOrder.Uint64(spanID[0:8])
19+
}

tracing/demos/cfs-throttling/stitch.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,17 @@ void cfs_clear_parent_span()
1616
*/
1717
import "C"
1818
import (
19-
"github.com/cloudflare/ebpf_exporter/v2/util"
19+
"github.com/cloudflare/ebpf_exporter/v2/tracing/demos"
2020
"go.opentelemetry.io/otel/trace"
2121
)
2222

2323
func cfsSetParentSpan(span trace.Span) {
24-
byteOrder := util.GetHostByteOrder()
25-
26-
traceID := span.SpanContext().TraceID()
27-
spanID := span.SpanContext().SpanID()
24+
traceIDHi, traceIDLo, spanID := demos.PropagationArgs(span)
2825

2926
C.cfs_set_parent_span(
30-
C.uint64_t(byteOrder.Uint64(traceID[0:8])),
31-
C.uint64_t(byteOrder.Uint64(traceID[8:16])),
32-
C.uint64_t(byteOrder.Uint64(spanID[0:8])),
27+
C.uint64_t(traceIDHi),
28+
C.uint64_t(traceIDLo),
29+
C.uint64_t(spanID),
3330
)
3431
}
3532

tracing/demos/sched/stitch.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,17 @@ void sched_clear_parent_span()
1616
*/
1717
import "C"
1818
import (
19-
"github.com/cloudflare/ebpf_exporter/v2/util"
19+
"github.com/cloudflare/ebpf_exporter/v2/tracing/demos"
2020
"go.opentelemetry.io/otel/trace"
2121
)
2222

2323
func schedSetParentSpan(span trace.Span) {
24-
byteOrder := util.GetHostByteOrder()
25-
26-
traceID := span.SpanContext().TraceID()
27-
spanID := span.SpanContext().SpanID()
24+
traceIDHi, traceIDLo, spanID := demos.PropagationArgs(span)
2825

2926
C.sched_set_parent_span(
30-
C.uint64_t(byteOrder.Uint64(traceID[0:8])),
31-
C.uint64_t(byteOrder.Uint64(traceID[8:16])),
32-
C.uint64_t(byteOrder.Uint64(spanID[0:8])),
27+
C.uint64_t(traceIDHi),
28+
C.uint64_t(traceIDLo),
29+
C.uint64_t(spanID),
3330
)
3431
}
3532

tracing/demos/sock/stitch.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void sock_set_parent_span(int sock_fd, uint64_t trace_id_hi, uint64_t trace_id_l
1616
*/
1717
import "C"
1818
import (
19-
"github.com/cloudflare/ebpf_exporter/v2/util"
19+
"github.com/cloudflare/ebpf_exporter/v2/tracing/demos"
2020
"go.opentelemetry.io/otel/trace"
2121
)
2222

@@ -25,15 +25,12 @@ func enableKernelTracing() {
2525
}
2626

2727
func sockSentParentSpan(fd uintptr, span trace.Span) {
28-
byteOrder := util.GetHostByteOrder()
29-
30-
traceID := span.SpanContext().TraceID()
31-
spanID := span.SpanContext().SpanID()
28+
traceIDHi, traceIDLo, spanID := demos.PropagationArgs(span)
3229

3330
C.sock_set_parent_span(
3431
C.int(fd),
35-
C.uint64_t(byteOrder.Uint64(traceID[0:8])),
36-
C.uint64_t(byteOrder.Uint64(traceID[8:16])),
37-
C.uint64_t(byteOrder.Uint64(spanID[0:8])),
32+
C.uint64_t(traceIDHi),
33+
C.uint64_t(traceIDLo),
34+
C.uint64_t(spanID),
3835
)
3936
}

0 commit comments

Comments
 (0)