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

chore(w3c): ensure last parent id is never set to 16 zeros #2808

Merged
merged 2 commits into from
Aug 8, 2024
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
8 changes: 2 additions & 6 deletions ddtrace/tracer/textmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ func getDatadogPropagator(cp *chainedPropagator) *propagator {
// if the reparenting ID is not set on the context, the span ID from datadog headers is used.
func overrideDatadogParentID(ctx, w3cCtx, ddCtx *spanContext) {
ctx.spanID = w3cCtx.spanID
if w3cCtx.reparentID != "" && w3cCtx.reparentID != "0000000000000000" {
if w3cCtx.reparentID != "" {
ctx.reparentID = w3cCtx.reparentID
} else if ddCtx != nil {
// NIT: could be done without using fmt.Sprintf? Is it worth it?
Expand Down Expand Up @@ -967,7 +967,7 @@ func composeTracestate(ctx *spanContext, priority int, oldState string) string {
if !ctx.isRemote {
b.WriteString(";p:")
b.WriteString(spanIDHexEncoded(ctx.SpanID(), 16))
} else if ctx.reparentID != "" && ctx.reparentID != "0000000000000000" {
} else if ctx.reparentID != "" {
b.WriteString(";p:")
b.WriteString(ctx.reparentID)
}
Expand Down Expand Up @@ -1202,10 +1202,6 @@ func parseTracestate(ctx *spanContext, header string) {
setPropagatingTag(ctx, "_dd.p."+keySuffix, val)
}
}
// if dd list-member is present and last parent is not set, set it to zeros
if ctx.reparentID == "" {
ctx.reparentID = "0000000000000000"
}
}
}

Expand Down
10 changes: 8 additions & 2 deletions ddtrace/tracer/textmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1756,7 +1756,7 @@ func TestEnvVars(t *testing.T) {
},
out: []uint64{8687463697196027922, 1311768467284833366},
priority: 1,
lastParent: "0000000000000000",
lastParent: "",
},
}
for i, tc := range tests {
Expand Down Expand Up @@ -1839,7 +1839,13 @@ func TestEnvVars(t *testing.T) {
if tc.priority != 0 {
sctx.setSamplingPriority(int(tc.priority), samplernames.Unknown)
}
assert.Equal(s.(*span).Meta["_dd.parent_id"], tc.lastParent)

if tc.lastParent == "" {
assert.Empty(s.(*span).Meta["_dd.parent_id"])
} else {
assert.Equal(s.(*span).Meta["_dd.parent_id"], tc.lastParent)
}

assert.Equal(true, sctx.updated)

headers := TextMapCarrier(map[string]string{})
Expand Down
Loading