Repository navigation
Reject malformed B3 span ids without exceptions (quick fix) - #13355
gh-worker-dd-mergequeue-cf854d[bot] merged 5 commits into
Conversation
A B3 span id or sampling priority a caller sends malformed, such as a span id with more than 16 hex digits, makes extraction throw NumberFormatException. The B3 interpreters handle it by invalidating the context and logging at debug level, but the logged exception still went to instrumentation telemetry: about 651K events from 10 orgs in 7 days on 1.68. Log NumberFormatException with EXCLUDE_TELEMETRY, as DatadogHttpCodec already does for invalid ids. Other exceptions from header handling may be tracer bugs and are still reported. Extraction behavior is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
Add LongStringUtils.parseUnsignedLongHexOrZero, a non-throwing twin of parseUnsignedLongHex that yields 0 for anything the throwing parse rejects, and use it for B3 span ids. A malformed span id no longer costs an exception per request: setSpanId returns false and the interpreter invalidates the context, as the exception path did. Zero is also what a malformed id parses to, so a zero result counts as malformed only when the input isn't all zeros; a literal zero span id is still accepted, as before. Whether B3 should reject it, as W3C does, is a separate question: the B3 spec does not say. The new parser counts significant digits within the parsed range. The throwing parser counts from the start of the string, so at a non-zero offset its 16-digit overflow guard can miss. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d51277d866
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
More details
Malformed B3 span IDs retain context-invalidation behavior without constructing parsing exceptions, while literal zero span IDs remain accepted.
🤖 Bits Code Review · Commit d51277d
Measures extraction with a valid, oversized or non-hex span id in both B3 styles, so the cost of rejecting malformed ids is visible. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
--- found by Codex Two non-blocking edge cases I found in the span ID parser:
|
AlexeyKuznetsov-DD
left a comment
There was a problem hiding this comment.
LGTM, left couple of minor comments and couple of findings flagged by codex.
Count only an ASCII '0' as padding when checking for more than 16 digits, as the throwing parse does, and accept a span id of any zero digits as zero, as DDSpanId.fromHex did. Test both, and pick an overflow input that a parser without the guard can't wrap to the expected zero. Also drop the quotes the new TableTest values don't need. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks, both were real. Fixed in 1796274:
|
There was a problem hiding this comment.
The PR avoids exceptions and telemetry for malformed B3 span IDs and adds extraction benchmarks. This update improves Unicode compatibility and overflow coverage, but one edge remains: a fullwidth zero followed by 16 ASCII zeros is accepted as span ID zero instead of invalidating the context.
🤖 Bits Code Review · Commit 1796274
|
/merge |
|
View all feedbacks in Devflow UI.
It will be processed automatically as soon as GitHub reports it as mergeable. View in MergeQueue UI.
The expected merge time in
|
A fullwidth zero followed by 16 ASCII zeros has 17 significant digits, which the old parser rejected, but the zero check accepted it. Count only ASCII '0' as padding there as well. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
More details
The PR avoids parsing exceptions and instrumentation telemetry for malformed B3 span IDs while preserving zero-ID behavior, with extraction benchmarks included. The latest change fixes acceptance of oversized Unicode-zero IDs by enforcing the parser’s length rules; the previously reported finding is resolved, and no issues remain open.
🤖 Bits Code Review · Commit 1922a65
What Does This Do
Stops a malformed B3 span ID from costing an exception on every request and from being reported to instrumentation telemetry.
LongStringUtils.parseUnsignedLongHexOrZero(s, start, len, lowerCaseOnly)is a twin ofparseUnsignedLongHexthat returns0for anything the throwing parser rejects: null, bad bounds, empty input, an illegal or (withlowerCaseOnly) uppercase character, or more than 16 significant digits. It's one pass with no allocation, in the same style asIntStringUtils.parseNonNegativeInt, which returns-1.setSpanIdnow returnsfalsefor a malformed ID, and both B3 interpreters then callinvalidateContext()and returnfalse, just as the exception path did. The rejection is logged at debug level without an exception, withEXCLUDE_TELEMETRY, asDatadogHttpCodecdoes for invalid IDs.0is also what a malformed ID parses to, so a zero result counts as malformed only when the input isn't all zeros. A0000000000000000span ID behaves exactly as before.NumberFormatExceptionis now logged withEXCLUDE_TELEMETRY(first commit). Any other exception from header handling may be a tracer bug and is still reported.Motivation
On 1.68, B3 extraction failures were about 651K instrumentation-telemetry events from 10 orgs in 7 days. All of them were
NumberFormatExceptionfrom a span ID with more than 16 significant hex digits, logged at debug ("Exception when extracting context"), and debug logs that carry an exception are still sent to telemetry:The B3 spec requires a span ID of "16 lower-hex characters", so these IDs are malformed and rejecting them is correct. They come from what callers send, not from tracer failures. Each one also cost an exception, including a stack trace and a
String.formatmessage, on the request path.Testing
LongStringUtilsTest(new): the non-throwing parse returns exactly whatparseUnsignedLongHexreturns wherever that parser succeeds, and0wherever it throws (null, bounds, empty, case, 17 significant digits, illegal characters, a sub-range). One more case pins significant-digit counting at a non-zero offset.B3HttpExtractorTest:EXCLUDE_TELEMETRY.B3HttpCodec: the behavior assertions and the zero-span-ID cases pass; only the no-exception/marker assertions fail. That's the evidence that extraction behavior is unchanged.datadog.trace.core.propagation.*pass, as doesDDSpanIdTest, andspotbugsMainis clean fordd-trace-apianddd-trace-core.B3SpanIdExtractBenchmark(new, JMH) extracts B3 headers with a valid, oversized (128-bit) or non-hex span ID, in both header styles. Results are below.Benchmark
JDK 17, 4 threads, 2 forks × 5 × 5 s,
-prof gc, master (98c28c6c01) vs this branch on the same machine. Debug logging is off, as in production.Malformed span ID: 5–6× faster, about 1.1–1.3 KB less allocation per extraction (the exception and its stack trace).
Valid span ID: no change. A 5-fork re-run (same settings) shows the same floor and the same median fork in both arms, and identical allocation.
The forks are multimodal, so the JMH means (b3multi 337.6 ± 13.4 vs 370.6 ± 51.1, b3single 261.1 ± 25.3 vs 237.8 ± 8.2) move in opposite directions depending on which arm drew an outlier fork.
Additional Notes
DDSpanId.ZEROis documented as "not allowed". This PR deliberately keeps today's behavior. Whether B3 should reject zero is a separate decision.parseUnsignedLongHex: its 16-digit overflow guard computeslen - firstNonZeroCharacter(s, start), and that helper returns an absolute index. At a non-zerostartwithlen > 16, the guard can miss and the value silently overflows. B3 always parses from index 0. The new parser counts within the range. I haven't changed the throwing parser here.W3CHttpCodechas the same pattern at a larger scale ("Exception when building context", about 6.2M events from 190 orgs in 7 days on 1.68). The new parser can serve it too; I'll do that separately.🤖 Generated with Claude Code