Skip to content

Commit

Permalink
remove last parent id 16 zeros
Browse files Browse the repository at this point in the history
  • Loading branch information
mabdinur committed Aug 6, 2024
1 parent 6674e13 commit 4429347
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
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

0 comments on commit 4429347

Please sign in to comment.