Skip to content

Commit

Permalink
add trace flags to OTLP export
Browse files Browse the repository at this point in the history
  • Loading branch information
dmathieu committed Apr 11, 2024
1 parent 1297d5f commit 76f4d87
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions exporters/otlp/otlptrace/internal/tracetransform/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ func span(sd tracesdk.ReadOnlySpan) *tracepb.Span {
s.ParentSpanId = psid[:]
}

flags := tracepb.SpanFlags_SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK
if sd.SpanContext().IsRemote() {
flags = flags | tracepb.SpanFlags_SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK
}
s.Flags = uint32(flags)

return s
}

Expand Down
29 changes: 29 additions & 0 deletions exporters/otlp/otlptrace/internal/tracetransform/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,34 @@ func TestStatus(t *testing.T) {
}
}

func TestFlags(t *testing.T) {
for _, tt := range []struct {
name string
readOnlySpan tracesdk.ReadOnlySpan
wantFlags uint32
}{
{
name: "with an empty span",
readOnlySpan: tracetest.SpanStub{}.Snapshot(),
wantFlags: 0x100,
},
{
name: "with a remote span context",
readOnlySpan: tracetest.SpanStub{
SpanContext: trace.NewSpanContext(trace.SpanContextConfig{
Remote: true,
}),
}.Snapshot(),
wantFlags: 0x300,
},
} {
t.Run(tt.name, func(t *testing.T) {
span := span(tt.readOnlySpan)
assert.Equal(t, tt.wantFlags, span.Flags)
})
}
}

func TestNilSpan(t *testing.T) {
assert.Nil(t, span(nil))
}
Expand Down Expand Up @@ -270,6 +298,7 @@ func TestSpanData(t *testing.T) {
SpanId: []byte{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8},
ParentSpanId: []byte{0xEF, 0xEE, 0xED, 0xEC, 0xEB, 0xEA, 0xE9, 0xE8},
TraceState: "key1=val1,key2=val2",
Flags: 0x1ff,
Name: spanData.Name,
Kind: tracepb.Span_SPAN_KIND_SERVER,
StartTimeUnixNano: uint64(startTime.UnixNano()),
Expand Down

0 comments on commit 76f4d87

Please sign in to comment.