Skip to content

Commit c0b55be

Browse files
author
elsa
committed
feat: use of span-id for trace to profile correlation
* host/host.go * interpreter/apmint/apmint.go * reporter/iface.go * support/ebpf/interpreter_dispatcher.ebpf.c * support/ebpf/tracer.ebpf.debug.amd64 * support/ebpf/tracer.ebpf.release.amd64 * support/ebpf/types.h * tracehandler/tracehandler.go * tracer/tracer.go
1 parent 1beadea commit c0b55be

File tree

9 files changed

+12
-2
lines changed

9 files changed

+12
-2
lines changed

host/host.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,5 @@ type Trace struct {
5656
APMRuntimeID string
5757
APMTraceID libpf.APMTraceID
5858
APMTransactionID libpf.APMTransactionID
59+
APMSpanID libpf.APMSpanID
5960
}

interpreter/apmint/apmint.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ func (i *Instance) Detach(ebpf interpreter.EbpfHandler, pid libpf.PID) error {
163163

164164
// NotifyAPMAgent sends out collected traces to the connected APM agent.
165165
// This is only called when layout-minor-version=1 (elastic's original Process Storage layout)
166+
// TODO: add support for span ID
166167
func (i *Instance) NotifyAPMAgent(
167168
pid libpf.PID, rawTrace *host.Trace, umTraceHash libpf.TraceHash, count uint16) {
168169
if rawTrace.APMTransactionID == libpf.InvalidAPMSpanID || i.socket == nil {

reporter/iface.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type TraceEventMeta struct {
3939
APMRuntimeID string
4040
APMTraceID libpf.APMTraceID
4141
APMTransactionID libpf.APMTransactionID
42+
APMSpanID libpf.APMSpanID
4243
}
4344

4445
type TraceReporter interface {

support/ebpf/interpreter_dispatcher.ebpf.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,15 @@ void maybe_add_apm_info(Trace *trace) {
163163
trace->apm_trace_id.as_int.hi = corr_buf.trace_id.as_int.hi;
164164
trace->apm_trace_id.as_int.lo = corr_buf.trace_id.as_int.lo;
165165
trace->apm_transaction_id.as_int = corr_buf.transaction_id.as_int;
166+
trace->apm_span_id.as_int = corr_buf.span_id.as_int;
166167
}
167168

168169
increment_metric(metricID_UnwindApmIntReadSuccesses);
169170

170171
// WARN: we print this as little endian
171-
DEBUG_PRINT("APM transaction ID: %016llX, flags: 0x%02X",
172-
trace->apm_transaction_id.as_int, corr_buf.trace_flags);
172+
DEBUG_PRINT("APM transaction ID: %016llX, APM span ID: %016llX, flags: 0x%02X",
173+
trace->apm_transaction_id.as_int, trace->apm_span_id.as_int,
174+
corr_buf.trace_flags);
173175
}
174176

175177
SEC("perf_event/unwind_stop")
512 Bytes
Binary file not shown.
176 Bytes
Binary file not shown.

support/ebpf/types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,8 @@ typedef struct Trace {
524524
u64 ktime;
525525
// The current COMM of the thread of this Trace.
526526
char comm[COMM_LEN];
527+
// APM span ID or all-zero if not present.
528+
ApmSpanID apm_span_id;
527529
// APM transaction ID or all-zero if not present.
528530
ApmSpanID apm_transaction_id;
529531
// APM trace ID or all-zero if not present.

tracehandler/tracehandler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ func (m *traceHandler) HandleTrace(bpfTrace *host.Trace) {
128128
APMRuntimeID: "", // filled in below
129129
APMTraceID: bpfTrace.APMTraceID,
130130
APMTransactionID: bpfTrace.APMTransactionID,
131+
APMSpanID: bpfTrace.APMSpanID,
131132
}
132133

133134
if !m.reporter.SupportsReportTraceEvent() {

tracer/tracer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,7 @@ func (t *Tracer) loadBpfTrace(raw []byte) *host.Trace {
861861
APMRuntimeID: C.GoString((*C.char)(unsafe.Pointer(&ptr.apm_runtime_id))),
862862
APMTraceID: *(*libpf.APMTraceID)(unsafe.Pointer(&ptr.apm_trace_id)),
863863
APMTransactionID: *(*libpf.APMTransactionID)(unsafe.Pointer(&ptr.apm_transaction_id)),
864+
APMSpanID: *(*libpf.APMSpanID)(unsafe.Pointer(&ptr.apm_span_id)),
864865
PID: libpf.PID(ptr.pid),
865866
TID: libpf.PID(ptr.tid),
866867
KTime: times.KTime(ptr.ktime),
@@ -874,6 +875,7 @@ func (t *Tracer) loadBpfTrace(raw []byte) *host.Trace {
874875
ptr.apm_runtime_id = [128]C.char{}
875876
ptr.apm_trace_id = C.ApmTraceID{}
876877
ptr.apm_transaction_id = C.ApmSpanID{}
878+
ptr.apm_span_id = C.ApmSpanID{}
877879
ptr.ktime = 0
878880
trace.Hash = host.TraceHash(xxh3.Hash128(raw).Lo)
879881

0 commit comments

Comments
 (0)