fix(otlp): cap tracestate at W3C 32-member limit after sampling writeback - #311
Open
detail-app[bot] wants to merge 1 commit into
Open
detail-app[bot] wants to merge 1 commit into
detail-app[bot] wants to merge 1 commit into
Conversation
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — This is a narrowly scoped OTLP bug fix that prevents sampling writeback from producing invalid 33-member W3C tracestate values while preserving existing You can add or adjust custom eligibility rules. Learn more. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Detail bug report: View on Detail
Fixes ENG-712
Bug
mergeOtTracestateinsrc/signals/otlp/traces.zigrebuilds a span'strace_stateafter a probabilistickeeptrace-sampler writes its threshold back asot=th:VALUE. It always emits a leadingot=list-member and then appends every existing non-ot=vendor entry with no count check, so a W3C-compliant 32-member incomingtrace_state(noot=entry) became a 33-member output — violating the W3C Trace Context normative cap of 32 list-members (§3.3.1.1 / §3.3.1.2 ABNFlist = list-member 0*31( ... )). That result is assigned straight tospan.trace_stateand re-serialized verbatim by the OTLP JSON and protobuf encoders, so a spec-non-conforming value went on the wire.The cap was lost in commit
b7b6419b: that refactor replaced the vendoredupdateTracestateInPlacehelper (which enforces the 32-member cap) with a hand-written merge to preserve non-th:ot=sub-keys (rv:,p:), but omitted the count cap and it was never re-added.Fix
Augmented
mergeOtTracestate's other-vendor loop with the 32-member cap:entry_countstarts at 1 (the always-emittedot=member) andif (entry_count >= 32) break;runs before each vendor append, dropping the least-recent (rightmost) vendor once the cap is reached.This preserves Edge's existing non-
th:ot=sub-key carry-through — it does not swap in the vendored helper, which wholesale-dropsot=and would striprv:/p:data and regress the existing tests. Non-th:ot=sub-keys live inside the singleot=member and so don't count against the member limit.Testing
src/signals/otlp/traces.zig:mergeOtTracestate - 32 vendors capped at W3C 32-member limit: the exact reported case — a compliant 32-member vendor-only input stays at 32 members (not 33) after theot=th:prepend.mergeOtTracestate - 31 vendors stays within cap, all preserved: boundary guard against over-truncation — at 31 vendors all are preserved (output =ot=+ 31 = 32).mergeOtTracestate - ot sub-keys preserved when vendor cap reached: guards against the footgun of adopting the vendored helper —ot=rv:abc,...keepsrv:(asot=rv:abc;th:VALUE) while still clamping to 32 members.processTraces - 100%-keep writeback keeps traceState within W3C 32-member limit: end-to-end through the publicprocessTracesStreamJSON path (decode → filter → sample → writeback → re-encode) with a 100%-keep policy, asserting the serializedtraceStatehas exactly 32 members, is prefixedot=th:0,, andv31=xis absent.zig build test --summary all(Debug and ReleaseSafe),zig fmt --check,ziglint, andzig build/zig build -Doptimize=ReleaseSafeall pass. Suite is green (523 pass / 1 skip; +4 net tests vs. baseline), no leaks.Automatic Fixes PRs can be configured here.