Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/src/trace/internal/tracestate-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export class TraceStateImpl implements TraceState {
Array.from(this._internalState.entries())
.reverse() // Use reverse same as original tracestate parse chain
.slice(0, MAX_TRACE_STATE_ITEMS)
.reverse() // Restore the internal reverse-insertion-order convention after truncation
);
}
}
Expand Down
15 changes: 9 additions & 6 deletions api/test/common/trace/tracestate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,10 @@ describe('TraceState', function () {
});

it('must truncate states with too many items', function () {
const state = createTraceState(
new Array(33)
.fill(0)
.map((_: null, num: number) => `a${num}=${num}`)
.join(',')
) as TraceStateImpl;
const items = new Array(33)
.fill(0)
.map((_: null, num: number) => `a${num}=${num}`);
const state = createTraceState(items.join(',')) as TraceStateImpl;
assert.deepStrictEqual(state['_keys']().length, 32);
assert.deepStrictEqual(state.get('a0'), '0');
assert.deepStrictEqual(state.get('a31'), '31');
Expand All @@ -103,6 +101,11 @@ describe('TraceState', function () {
undefined,
'should truncate from the tail'
);
assert.deepStrictEqual(
state.serialize(),
items.slice(0, 32).join(','),
'should preserve the original member order after truncation'
);
});

it('should not count invalid items towards max limit', function () {
Expand Down