Skip to content

Parse the W3C traceparent without throwing - #13356

Draft
dougqh wants to merge 2 commits into
dougqh/lazy-extracted-id-hexfrom
dougqh/w3c-traceparent-no-throw
Draft

dougqh wants to merge 2 commits into
dougqh/lazy-extracted-id-hexfrom
dougqh/w3c-traceparent-no-throw

Conversation

@dougqh

@dougqh dougqh commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

What Does This Do

Rejects a malformed W3C traceparent header without throwing an exception. Extraction results are unchanged.

  • parseTraceParent and parseRequiredTraceParent now return whether the header is valid, instead of throwing IllegalStateException (length, version, zero IDs, separator) or NumberFormatException (non-hex characters).
  • The hex parts are parsed with LongStringUtils.parseUnsignedLongHexOrZero, which returns 0 instead of throwing:
    • the low half of the trace ID and the span ID may not be zero, so a zero result rejects them, as before;
    • the version, the high half of the trace ID and the flags may legitimately be zero, so for those a zero result is rejected only if the characters aren't all 0.
  • build() still falls back to onlyTagContext() and buildForMerge() still returns null. The tracestate parsing keeps its own try/catch.
  • A rejection logs a fixed reason at debug level ("Ignoring invalid traceparent '…': too short"), with no exception and no message concatenation.

Motivation

On 1.68, the catch in build() ("Exception when building context") was the single largest source of instrumentation telemetry errors: about 6.2M events from 190 orgs in 7 days. That's 4.9M IllegalStateException events from parseTraceParentHeader, plus 1.3M NumberFormatException events from LongStringUtils. These are headers callers send malformed, not tracer failures. Each one also cost an exception, with a stack trace and a string-concatenated message, on the request path.

Testing

  • W3CHttpExtractorTest.extractTraceparent already pins the extraction result for each malformed form (length, version, uppercase and non-ASCII characters in the trace and span IDs, zero IDs, separators). I added rows for the zero-check paths that weren't covered: a non-hex or uppercase version, and non-hex or uppercase flags.
  • New: malformedTraceparentIsRejectedWithoutAnException. For five malformed forms, no context is extracted, a debug "Ignoring invalid traceparent" is logged, and no exception is logged.
  • Against the original W3CHttpCodec: the 5 new no-exception cases fail and the other 1,414 propagation tests pass, including every extractTraceparent row, old and new, and CompoundExtractionGoldenTest for the merge path. That's the evidence the extraction behavior is unchanged.
  • With this change: all 1,419 tests in datadog.trace.core.propagation.* and LongStringUtilsTest pass, and :dd-trace-core:spotbugsMain is clean.

Additional Notes

🤖 Generated with Claude Code

@dougqh dougqh added type: bug fix Bug fix comp: core Tracer core tag: performance Performance related changes comp: context propagation Trace context propagation tag: ai generated Largely based on code generated by an AI or LLM labels Nov 10, 2026
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
• Patch Coverage: 91.49%
• Overall Coverage: 59.50% (+0.00%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: e779675 | Docs | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Nov 10, 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 14.05 s 13.96 s [-0.2%; +1.4%] (no difference)
startup:insecure-bank:tracing:Agent 12.90 s 12.98 s [-1.2%; -0.0%] (maybe better)
startup:petclinic:appsec:Agent 17.19 s 17.52 s [-6.0%; +2.4%] (no difference)
startup:petclinic:iast:Agent 17.53 s 17.68 s [-1.8%; +0.1%] (no difference)
startup:petclinic:profiling:Agent 16.77 s 17.45 s [-9.2%; +1.4%] (unstable)
startup:petclinic:sca:Agent 17.80 s 17.64 s [-0.1%; +1.9%] (no difference)
startup:petclinic:tracing:Agent 16.67 s 16.71 s [-1.1%; +0.6%] (no difference)

Commit: e779675f · 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.

@dougqh dougqh added the tag: telemetry error reported Reported by error telemetry label Nov 10, 2026
dougqh and others added 2 commits November 11, 2026 20:41
The same LongStringUtils.parseUnsignedLongHexOrZero, with its test, as
#13355 adds on master, so the W3C traceparent parse on this stack can use
it. Drop this commit when rebasing onto a master that has #13355.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A malformed traceparent made parseTraceParent throw IllegalStateException
or NumberFormatException, caught in build() and buildForMerge(): an
exception per request, and the largest source of instrumentation
telemetry errors on 1.68 (about 6.2M events from 190 orgs in 7 days).

parseTraceParent and parseRequiredTraceParent now return whether the
header is valid, and parse hex parts with parseUnsignedLongHexOrZero.
The low half of the trace id and the span id may not be zero, so a zero
result rejects them as before; the version, the trace id's high half and
the flags may be zero, so for those a zero result is rejected only when
the characters aren't all zeros. A rejection logs its reason at debug
level, without an exception. Extraction results are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

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

Labels

comp: context propagation Trace context propagation comp: core Tracer core tag: ai generated Largely based on code generated by an AI or LLM tag: performance Performance related changes tag: telemetry error reported Reported by error telemetry type: bug fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant