Skip to content

Commit

Permalink
Populate span.lt with the 128-bit version of span.t
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Slotin committed Feb 17, 2021
1 parent 628ebae commit 61befb7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
3 changes: 0 additions & 3 deletions instrumentation_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func TestTracingHandlerFunc_Write(t *testing.T) {
assert.Empty(t, span.CorrelationType)
assert.Empty(t, span.CorrelationID)
assert.False(t, span.ForeignTrace)
assert.Empty(t, span.W3CTraceID)
assert.Empty(t, span.Ancestor)

require.IsType(t, instana.HTTPSpanData{}, span.Data)
Expand Down Expand Up @@ -108,7 +107,6 @@ func TestTracingHandlerFunc_WriteHeaders(t *testing.T) {
assert.Empty(t, span.CorrelationType)
assert.Empty(t, span.CorrelationID)
assert.False(t, span.ForeignTrace)
assert.Empty(t, span.W3CTraceID)
assert.Empty(t, span.Ancestor)

require.IsType(t, instana.HTTPSpanData{}, span.Data)
Expand Down Expand Up @@ -171,7 +169,6 @@ func TestTracingHandlerFunc_W3CTraceContext(t *testing.T) {
assert.Empty(t, span.CorrelationType)
assert.Empty(t, span.CorrelationID)
assert.True(t, span.ForeignTrace)
assert.Equal(t, "00000000000000010000000000000002", span.W3CTraceID)
assert.Equal(t, &instana.TraceReference{
TraceID: "1234",
ParentID: "5678",
Expand Down
18 changes: 7 additions & 11 deletions json_span.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ type Span struct {
TraceIDHi int64
ParentID int64
SpanID int64
W3CTraceID string
Ancestor *TraceReference
Timestamp uint64
Duration uint64
Expand Down Expand Up @@ -162,14 +161,6 @@ func newSpan(span *spanS) Span {
delete(span.Tags, syntheticCallTag)
}

// populate W3C trace ID only if the original incoming value was 128-bits long
// we cannot rely on TraceIDHi here, as we might be using the 64-bit ID from
// X-Instana-T and still have traceparent with 128-bit value
longTraceID := span.context.W3CContext.Parent().TraceID
if len(longTraceID) == 32 && longTraceID[:16] != "0000000000000000" {
sp.W3CTraceID = longTraceID
}

if len(span.context.Links) > 0 {
ancestor := span.context.Links[0]
sp.Ancestor = &TraceReference{
Expand All @@ -193,11 +184,16 @@ func (sp Span) MarshalJSON() ([]byte, error) {
parentID = FormatID(sp.ParentID)
}

var longTraceID string
if sp.TraceIDHi != 0 {
longTraceID = FormatLongID(sp.TraceIDHi, sp.TraceID)
}

return json.Marshal(struct {
TraceReference

SpanID string `json:"s"`
W3CTraceID string `json:"lt,omitempty"`
LongTraceID string `json:"lt,omitempty"`
Timestamp uint64 `json:"ts"`
Duration uint64 `json:"d"`
Name string `json:"n"`
Expand All @@ -217,7 +213,7 @@ func (sp Span) MarshalJSON() ([]byte, error) {
parentID,
},
FormatID(sp.SpanID),
sp.W3CTraceID,
longTraceID,
sp.Timestamp,
sp.Duration,
sp.Name,
Expand Down

0 comments on commit 61befb7

Please sign in to comment.