Skip to content

Decouple W3C lastParentId from shared propagation-tag mutation#11702

Draft
dougqh wants to merge 1 commit into
masterfrom
dougqh/ptags-decouple-lastparentid
Draft

Decouple W3C lastParentId from shared propagation-tag mutation#11702
dougqh wants to merge 1 commit into
masterfrom
dougqh/ptags-decouple-lastparentid

Conversation

@dougqh

@dougqh dougqh commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

What

Stop mutating the (trace-level, shared) PropagationTags with the injecting span's id at W3C inject time; supply it as a parameter instead.

Why

W3CHttpCodec.injectTraceState did:

propagationTags.updateLastParentId(DDSpanId.toHexStringPadded(context.getSpanId()));
String tracestate = propagationTags.headerValue(W3C);

But getPropagationTags() routes to the root (getRootSpanContextOrThis()), so the field is effectively shared across the segment. Concurrent sibling injects race on it — span A writes A, span B writes B, A reads back B and emits the wrong p: (W3C last-parent-id). It also thrashed the W3C header cache (invalidated on every differing id). Pre-existing; not introduced by the per-span sharing work (#11701).

How

  • New PropagationTags.headerValue(HeaderType, CharSequence lastParentIdOverride). W3CHttpCodec passes context.getSpanId(); W3CPTagsCodec uses the override for p:, falling back to the stored inbound last-parent-id when there's no override (span-link traceState, extraction reads).
  • No inject-time mutation of the shared tags → no race, no cross-talk between sibling injects, and the inbound last-parent-id is preserved for its ctor/extraction reads.
  • updateLastParentId is now unused and removed (it was the only inject-time mutator; the inbound value is set at construction).

Deliberately out of scope

OPM stamping is left as-is. It writes a process-constant local OPM, so concurrent injects are idempotent — no real race — and OPM is new; let it settle. Same-shape decouple is a clean future follow-up (or it rides the TraceSegment migration).

Test / validation

  • PropagationTagsLastParentIdTest — override supplies p:; sibling injects don't cross-talk; inbound p: preserved and unmutated by override use.
  • Full dd-trace-core propagation + span-build suite green (1947 tests, 0 failures), incl. W3CHttpInjectorTest.updateLastParentIdOnChildSpan, the 611 W3CPropagationTags cases, and span-link traceState.

Relationship

Step 2 of the PTags-per-segment work; pairs with #11701 (share parent's PTags for local children — the allocation win). Both are early steps toward a first-class TraceSegment.

🤖 Generated with Claude Code

Injecting a W3C tracestate wrote the injecting span's id into the
(trace-level, shared via getRootSpanContextOrThis) PropagationTags via
updateLastParentId, then read it back to build the `p:` member.
Concurrent sibling injects race on that shared field -- A writes A, B
writes B, A can emit B as its last-parent.

Supply the injecting span's id as a parameter instead:
PropagationTags.headerValue(HeaderType, lastParentIdOverride).
W3CHttpCodec passes context.getSpanId(); the W3C codec uses the override
for `p:`, falling back to the stored inbound last-parent-id for
non-inject callers (span-link traceState). No inject-time mutation of
the shared tags -> no race, no cross-talk between sibling injects, and
the inbound last-parent-id is preserved for its ctor/extraction reads.

updateLastParentId is now unused and removed (it was the only
inject-time mutator; the inbound value is set at construction).

OPM stamping is left as-is on purpose: it writes a process-constant
local OPM, so concurrent injects are idempotent (no race).

Full dd-trace-core propagation + span-build suite passes (1947 tests).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@dd-octo-sts

dd-octo-sts Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 13.92 s 13.93 s [-0.8%; +0.7%] (no difference)
startup:insecure-bank:tracing:Agent 12.91 s 12.99 s [-1.5%; +0.4%] (no difference)
startup:petclinic:appsec:Agent 16.68 s 16.65 s [-1.0%; +1.3%] (no difference)
startup:petclinic:iast:Agent 16.79 s 16.53 s [-2.6%; +5.9%] (no difference)
startup:petclinic:profiling:Agent 16.72 s 16.67 s [-0.7%; +1.3%] (no difference)
startup:petclinic:sca:Agent 15.86 s 16.21 s [-9.7%; +5.3%] (unstable)
startup:petclinic:tracing:Agent 15.91 s 15.64 s [-2.4%; +5.8%] (no difference)

Commit: 6f422485 · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Pipelines

Fix all issues with BitsAI

⚠️ Warnings

🚦 2 Pipeline jobs failed

Run system tests | main / End-to-end #5 / play 5   View in Datadog   GitHub Actions

Run system tests | Check system tests success   View in Datadog   GitHub Actions

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 6f42248 | Docs | Datadog PR Page | Give us feedback!

@datadog-datadog-prod-us1-2

Copy link
Copy Markdown
Contributor

Bits is fixing CI

🟢 Investigated · 🔵 Preparing fix · ⚪ Validate · ⚪ Ready


View in Datadog | Commit 6f42248

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant