Commit cfad5eb
Fix TraceState.update to only update already existing keys (#5543)
* Fix TraceState.update dropping all entries at the 32-key limit
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>
* Preserve upsert in TraceState.update; guard only new key at 32-key limit
Address review feedback: instead of restricting update() to existing keys
(a breaking change for samplers relying on upsert), keep upsert behavior and
only return the tracestate unchanged when adding a *new* key would exceed the
32-key maximum. Fixes the silent drop of all entries at capacity.
* Document upsert behaviour of TraceState.update
Note in the update() docstring that it performs an upsert and that this
intentionally goes beyond the spec's update definition, as requested in
review. Docstring-only change; no behavior change.
* Fix precommit: format update() length guard onto one line
---------
Signed-off-by: Md. Amdadul Bari Imad <amdadulbari@gmail.com>
Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
Co-authored-by: Leighton Chen <lechen@microsoft.com>1 parent ab22674 commit cfad5eb
3 files changed
Lines changed: 46 additions & 3 deletions
File tree
- .changelog
- opentelemetry-api
- src/opentelemetry/trace
- tests/trace
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
314 | 314 | | |
315 | 315 | | |
316 | 316 | | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
317 | 325 | | |
318 | 326 | | |
319 | 327 | | |
320 | 328 | | |
321 | 329 | | |
322 | 330 | | |
323 | 331 | | |
324 | | - | |
325 | | - | |
326 | | - | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
327 | 336 | | |
328 | 337 | | |
329 | 338 | | |
330 | 339 | | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
331 | 346 | | |
332 | 347 | | |
333 | 348 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
54 | 81 | | |
55 | 82 | | |
56 | 83 | | |
| |||
0 commit comments