fix(api): preserve tracestate member order when truncating over 32 items - #7072
fix(api): preserve tracestate member order when truncating over 32 items#7072zigzagdev wants to merge 2 commits into
Conversation
TraceStateImpl truncated over-limit tracestate entries by slicing the reversed entry list but never reversing it back, so the internal map's reverse-insertion-order convention was broken and serialize() emitted members in reverse order.
The existing truncation test only checked item count and key presence, so the serialize() order regression went undetected.
|
Welcome, contributor! Thank you for your contribution to opentelemetry-js. Important reminders:
|
Pull request dashboard statusWaiting on reviewers · refreshed 2026-09-06 07:15 UTC Review the latest changes. Status above doesn't look right?
|
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) truncates tracestate entries when there are more than 32 members.The truncation logic reversed the entry list to slice off the oldest members, but never reversed the result back before rebuilding the internal
Map, breaking the map's reverse-insertion-order convention.As a result,
serialize()on a truncatedTraceStateImplemitted members in reverse order, violating the W3C tracestate ordering requirement (most recently updated member first).Fixes # (issue)
Short description of the changes
.reverse()call afterslice()in_parse()so the internal map's insertion order is restored after truncation.serialize()preserves the original member order after truncating over-limit entries.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 configuration
Ran
api/test/common/trace/tracestate.test.ts(transpile-only mocha run) — all 12 tests pass, including the new order assertion.Manually reproduced the truncation logic in a standalone Node script with a 5-member tracestate truncated to 3 members, confirming the serialized order matches the expected "e=5,d=4,c=3" (previously produced "c=3,d=4,e=5").
Test A:
npx mocha 'test/common/trace/tracestate.test.tsinapi/Checklist: