Skip to content

Commit

Permalink
add span flags to links too
Browse files Browse the repository at this point in the history
  • Loading branch information
dmathieu committed Apr 11, 2024
1 parent 0d9b925 commit 55bc772
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
19 changes: 13 additions & 6 deletions exporters/otlp/otlptrace/internal/tracetransform/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,7 @@ func span(sd tracesdk.ReadOnlySpan) *tracepb.Span {
if psid := sd.Parent().SpanID(); psid.IsValid() {
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)
s.Flags = buildSpanFlags(sd.SpanContext())

return s
}
Expand Down Expand Up @@ -152,16 +147,28 @@ func links(links []tracesdk.Link) []*tracepb.Span_Link {
tid := otLink.SpanContext.TraceID()
sid := otLink.SpanContext.SpanID()

flags := buildSpanFlags(otLink.SpanContext)

sl = append(sl, &tracepb.Span_Link{
TraceId: tid[:],
SpanId: sid[:],
Attributes: KeyValues(otLink.Attributes),
DroppedAttributesCount: uint32(otLink.DroppedAttributeCount),
Flags: flags,
})
}
return sl
}

func buildSpanFlags(sc trace.SpanContext) uint32 {
flags := tracepb.SpanFlags_SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK
if sc.IsRemote() {
flags = flags | tracepb.SpanFlags_SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK
}

return uint32(flags)
}

// spanEvents transforms span Events to an OTLP span events.
func spanEvents(es []tracesdk.Event) []*tracepb.Span_Event {
if len(es) == 0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func TestLinks(t *testing.T) {
TraceId: []uint8{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
SpanId: []uint8{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
DroppedAttributesCount: 3,
Flags: 0x100,
}
assert.Equal(t, expected, got[0])

Expand Down

0 comments on commit 55bc772

Please sign in to comment.