Repository navigation
Conversation
TraceStateImpl previously dropped the entire tracestate whenever the raw header exceeded 512 characters. @opentelemetry/core's TraceState instead accumulates valid members left-to-right and skips only the members that would push the running length over the limit, keeping shorter members that still fit. Port the same accumulation logic so the two implementations behave consistently.
…er is skipped Mirrors the equivalent @opentelemetry/core test to cover the accumulation-based length truncation.
|
Welcome, contributor! Thank you for your contribution to opentelemetry-js. Important reminders:
|
Pull request dashboard statusWaiting on the author · refreshed 2026-10-18 01:28 UTC Respond to 1 review item (e.g. link a commit, explain why not, ask a follow-up):
Status above doesn't look right?
|
|
The tracestate class from the API was deprecated in #6459 @open-telemetry/javascript-approvers should we revisit this? |
pichlermarc
left a comment
There was a problem hiding this comment.
Hi @zigzagdev - I'm open to aligning both implementations, but I think we should copy the TraceState impl from core verbatim where possible to avoid differences in behavior.
suggestion: copy TraceState from @opentelemetry/core, adjust class name and formatting where needed (you may also need to adjust tests)
|
Hi @zigzagdev — just a friendly reminder that this pull request is waiting on you. The dashboard status comment has the open items and is kept current.
|
Parsing is now deferred until the state is actually read, and the tracked length is updated incrementally on set/unset so mutations that would exceed the W3C 512-char limit are rejected without re-serializing the whole state.
Add cases for set()/unset() returning the same instance when a mutation would be a no-op or exceed the max length, and update the parse tests to match the new skip/truncate behavior.
|
I'll copy |
Which problem is this PR solving?
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.TraceStateImpl(in@opentelemetry/api,api/src/trace/internal/tracestate-impl.ts) dropped the entire tracestate whenever the raw header string exceeded 512 characters (if (rawTraceState.length > MAX_TRACE_STATE_LEN) return;). This diverges from@opentelemetry/core'sTraceState(packages/opentelemetry-core/src/trace/TraceState.ts), which instead accumulates valid members from the front (most recently updated first) and only skips the individual member that would push the running length over 512, continuing to check the remaining, potentially shorter, members.Because
createTraceState(api, deprecated) andTraceState(core, used in practice) are meant to have equivalent parsing semantics, so this inconsistency meant the same raw tracestate header could be parsed completely differently depending on which implementation handled it.Fixes # (issue)
Short description of the changes
TraceStateImpl._parse()to accumulate members left-to-right with a running length budget, matching@opentelemetry/core'sTraceState._getState()behavior: a member that would exceed the 512-character limit is skipped, but subsequent (shorter) members are still evaluated instead of discarding the whole state.break, replacing the previous separate post-processing step.@opentelemetry/core's equivalent case: a state with an oversized member followed by a short one keeps the short member instead of dropping everything.Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configurationapi/test/common/trace/tracestate.test.ts(transpile-only mocha run) — all 13 tests pass, including the new test.eslinton the changed files — no issues.tsc --noEmit— only pre-existing, unrelated errors from a missing generatedsrc/version.tsfile (not touched by this change).npx mocha 'test/common/trace/tracestate.test.ts'inapi/Checklist: