Skip to content

Commit

Permalink
tracer: Fix TestMalformedTID so it passes on its own (#2257)
Browse files Browse the repository at this point in the history
  • Loading branch information
evanj authored Oct 13, 2023
1 parent b9c67e8 commit 26fb2f4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
27 changes: 11 additions & 16 deletions ddtrace/tracer/textmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2093,52 +2093,47 @@ func TestPropagatingTagsConcurrency(_ *testing.T) {
}

func TestMalformedTID(t *testing.T) {
assert := assert.New(t)
tracer := newTracer()
internal.SetGlobalTracer(tracer)
defer tracer.Stop()
defer internal.SetGlobalTracer(&internal.NoopTracer{})

t.Run("datadog, short tid", func(t *testing.T) {
t.Setenv(headerPropagationStyleExtract, "datadog")
tracer := newTracer()
defer tracer.Stop()
headers := TextMapCarrier(map[string]string{
DefaultTraceIDHeader: "1234567890123456789",
DefaultParentIDHeader: "987654321",
traceTagsHeader: "_dd.p.tid=1234567890abcde",
})
sctx, err := tracer.Extract(headers)
assert.Nil(err)
assert.Nil(t, err)
root := tracer.StartSpan("web.request", ChildOf(sctx)).(*span)
root.Finish()
assert.NotContains(root.Meta, keyTraceID128)
assert.NotContains(t, root.Meta, keyTraceID128)
})

t.Run("datadog, malformed tid", func(t *testing.T) {
t.Setenv(headerPropagationStyleExtract, "datadog")
tracer := newTracer()
defer tracer.Stop()
headers := TextMapCarrier(map[string]string{
DefaultTraceIDHeader: "1234567890123456789",
DefaultParentIDHeader: "987654321",
traceTagsHeader: "_dd.p.tid=XXXXXXXXXXXXXXXX",
})
sctx, err := tracer.Extract(headers)
assert.Nil(err)
assert.Nil(t, err)
root := tracer.StartSpan("web.request", ChildOf(sctx)).(*span)
root.Finish()
assert.NotContains(root.Meta, keyTraceID128)
assert.NotContains(t, root.Meta, keyTraceID128)
})

t.Run("datadog, valid tid", func(t *testing.T) {
t.Setenv(headerPropagationStyleExtract, "datadog")
tracer := newTracer()
defer tracer.Stop()
headers := TextMapCarrier(map[string]string{
DefaultTraceIDHeader: "1234567890123456789",
DefaultParentIDHeader: "987654321",
traceTagsHeader: "_dd.p.tid=640cfd8d00000000",
})
sctx, err := tracer.Extract(headers)
assert.Nil(err)
assert.Nil(t, err)
root := tracer.StartSpan("web.request", ChildOf(sctx)).(*span)
root.Finish()
assert.Equal("640cfd8d00000000", root.Meta[keyTraceID128])
assert.Equal(t, "640cfd8d00000000", root.Meta[keyTraceID128])
})
}
4 changes: 3 additions & 1 deletion ddtrace/tracer/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,8 +712,9 @@ func TestTracerStartSpanOptions128(t *testing.T) {
tracer := newTracer()
internal.SetGlobalTracer(tracer)
defer tracer.Stop()
assert := assert.New(t)
defer internal.SetGlobalTracer(&internal.NoopTracer{})
t.Run("64-bit-trace-id", func(t *testing.T) {
assert := assert.New(t)
opts := []StartSpanOption{
WithSpanID(987654),
}
Expand All @@ -728,6 +729,7 @@ func TestTracerStartSpanOptions128(t *testing.T) {
assert.Equal(s.Context().TraceID(), binary.BigEndian.Uint64(idBytes[8:]))
})
t.Run("128-bit-trace-id", func(t *testing.T) {
assert := assert.New(t)
// Enable 128 bit trace ids
t.Setenv("DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED", "true")
opts128 := []StartSpanOption{
Expand Down

0 comments on commit 26fb2f4

Please sign in to comment.