Skip to content

Commit

Permalink
Send span.tp: true if span parent did not come from Instana
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Slotin committed Feb 16, 2021
1 parent ed05e5f commit 17ef7c0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions instrumentation_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func TestTracingHandlerFunc_W3CTraceContext(t *testing.T) {
assert.False(t, span.Synthetic)
assert.Empty(t, span.CorrelationType)
assert.Empty(t, span.CorrelationID)
assert.True(t, span.ForeignTrace)

require.IsType(t, instana.HTTPSpanData{}, span.Data)
data := span.Data.(instana.HTTPSpanData)
Expand Down
4 changes: 4 additions & 0 deletions json_span.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ type Span struct {
Synthetic bool
CorrelationType string
CorrelationID string
ForeignTrace bool
}

func newSpan(span *spanS) Span {
Expand All @@ -142,6 +143,7 @@ func newSpan(span *spanS) Span {
Ec: span.ErrorCount,
CorrelationType: span.Correlation.Type,
CorrelationID: span.Correlation.ID,
ForeignTrace: span.context.ForeignTrace,
Kind: int(data.Kind()),
Data: data,
}
Expand Down Expand Up @@ -183,6 +185,7 @@ func (sp Span) MarshalJSON() ([]byte, error) {
Synthetic bool `json:"sy,omitempty"`
CorrelationType string `json:"crtp,omitempty"`
CorrelationID string `json:"crid,omitempty"`
ForeignTrace bool `json:"tp,omitempty"`
}{
FormatID(sp.TraceID),
parentID,
Expand All @@ -198,6 +201,7 @@ func (sp Span) MarshalJSON() ([]byte, error) {
sp.Synthetic,
sp.CorrelationType,
sp.CorrelationID,
sp.ForeignTrace,
})
}

Expand Down
5 changes: 5 additions & 0 deletions span_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type SpanContext struct {
Baggage map[string]string // initialized on first use
// The W3C trace context
W3CContext w3ctrace.Context
// Whether the used trace ID came from 3rd party, e.g. W3C Trace Context
ForeignTrace bool
// Correlation is the correlation data sent by the frontend EUM script
Correlation EUMCorrelationData
}
Expand All @@ -54,8 +56,10 @@ func NewRootSpanContext() SpanContext {
// ignore the parent context if it contains neither Instana trace and span IDs
// nor a W3C trace context
func NewSpanContext(parent SpanContext) SpanContext {
var foreignTrace bool
if parent.TraceIDHi == 0 && parent.TraceID == 0 && parent.SpanID == 0 {
parent = restoreFromW3CTraceContext(parent.W3CContext)
foreignTrace = true
}

if parent.TraceIDHi == 0 && parent.TraceID == 0 && parent.SpanID == 0 {
Expand All @@ -64,6 +68,7 @@ func NewSpanContext(parent SpanContext) SpanContext {

c := parent.Clone()
c.SpanID, c.ParentID = randomID(), parent.SpanID
c.ForeignTrace = foreignTrace

// update W3C trace context parent
if c.W3CContext.IsZero() {
Expand Down
1 change: 1 addition & 0 deletions span_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func TestNewSpanContext_FromW3CTraceContext(t *testing.T) {
RawParent: "00-00000000000000010000000000000002-" + instana.FormatID(c.SpanID) + "-01",
RawState: "in=1234;5678,vendor1=data",
},
ForeignTrace: true,
}, c)
}

Expand Down

0 comments on commit 17ef7c0

Please sign in to comment.