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

tracer: Fix TestMalformedTID so it passes on its own #2257

Merged
merged 4 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading