Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update OTLP SpanData transform #614

Merged
merged 5 commits into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions exporters/otlp/internal/transform/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ func span(sd *export.SpanData) *tracepb.Span {
if sd == nil {
return nil
}
return &tracepb.Span{

s := &tracepb.Span{
TraceId: sd.SpanContext.TraceID[:],
SpanId: sd.SpanContext.SpanID[:],
ParentSpanId: sd.ParentSpanID[:],
Status: status(sd.StatusCode, sd.StatusMessage),
StartTimeUnixNano: uint64(sd.StartTime.UnixNano()),
EndTimeUnixNano: uint64(sd.EndTime.UnixNano()),
Expand All @@ -82,6 +82,12 @@ func span(sd *export.SpanData) *tracepb.Span {
DroppedEventsCount: uint32(sd.DroppedMessageEventCount),
DroppedLinksCount: uint32(sd.DroppedLinkCount),
}

if sd.ParentSpanID.IsValid() {
s.ParentSpanId = sd.ParentSpanID[:]
}

return s
}

// status transform a span code and message into an OTLP span status.
Expand Down
9 changes: 9 additions & 0 deletions exporters/otlp/internal/transform/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,12 @@ func TestSpanData(t *testing.T) {
t.Fatalf("transformed span differs %v\n", diff)
}
}

// Empty parent span ID should be treated as root span.
func TestRootSpanData(t *testing.T) {
rs := SpanData([]*export.SpanData{{}})[0]
got := rs.GetInstrumentationLibrarySpans()[0].GetSpans()[0].GetParentSpanId()

// Empty means root span.
assert.Nil(t, got, "incorrect transform of root parent span ID")
}