Fix TraceState.update to only update already existing keys - #5543
Open
amdadulbari wants to merge 1 commit into
Open
Fix TraceState.update to only update already existing keys#5543amdadulbari wants to merge 1 commit into
amdadulbari wants to merge 1 commit into
Conversation
amdadulbari
force-pushed
the
fix/tracestate-update-32-key-limit
branch
from
August 13, 2026 04:40
264b58c to
7c471e5
Compare
xrmx
reviewed
Aug 14, 2026
amdadulbari
force-pushed
the
fix/tracestate-update-32-key-limit
branch
from
August 14, 2026 08:39
7c471e5 to
a4d1fe8
Compare
xrmx
approved these changes
Aug 14, 2026
xrmx
left a comment
Contributor
There was a problem hiding this comment.
Nit in the changelog (please also update the PR title), thanks a lot!
amdadulbari
force-pushed
the
fix/tracestate-update-32-key-limit
branch
from
August 14, 2026 13:36
a4d1fe8 to
5466132
Compare
Author
Done, updated the changelog to your suggested wording and renamed the PR title to match. Thanks for the review! |
Pull request dashboard statusWaiting on maintainers · refreshed 2026-08-14 18:36 UTC Merge when ready. Status above doesn't look right?
|
TraceState.update() builds a new entry list and passes it to the constructor, which discards everything and returns an empty TraceState when the list exceeds the 32-key W3C limit. As a result, upserting a new key into a tracestate that already holds 32 entries silently wiped all 32 existing key/value pairs, contradicting update()'s documented contract that "the same tracestate will be returned". Guard the limit the way add() already does, but only for genuinely new keys, so updates to existing keys at capacity keep working. Add tests for both cases. Signed-off-by: Md. Amdadul Bari Imad <amdadulbari@gmail.com>
amdadulbari
force-pushed
the
fix/tracestate-update-32-key-limit
branch
from
August 14, 2026 18:32
49865cc to
f597006
Compare
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.
Description
TraceState.update()can silently discard every existing entry.update()builds a new list of entries and passes it to theTraceStateconstructor. When a tracestate already holds the W3C maximum of 32 members andupdate()is called with a new key, the new list has 33 entries; the constructor detectslen(entries) > 32, logs a warning, and returns an emptyTraceState. So upserting one new key into a full tracestate wipes all 32 existing key/value pairs.This also contradicts
update()'s own docstring, which states that if the pair "results in tracestate that violates tracecontext specification ... the same tracestate will be returned."The sibling
add()already guards this limit;update()did not. This change applies the same guard, but only when the key is genuinely new, so updating the value of an existing key while at capacity keeps working.Type of change
How Has This Been Tested?
Added two unit tests in
opentelemetry-api/tests/trace/test_tracestate.py:test_tracestate_update_at_capacity_new_key_preserved— updating with a new key at 32 entries preserves the existing 32 (fails before this change:len == 0).test_tracestate_update_at_capacity_existing_key— updating an existing key at capacity still applies and stays within the limit.python -m pytest opentelemetry-api/tests/tracepasses (55 tests);ruff check/ruff formatare clean on the changed files.Checklist
.changelog/).