Skip to content

Commit c57247f

Browse files
logaretmclaude
andcommitted
fix(test): Make scope leak test deterministic
Use an explicit traceId in the inner scope instead of relying on generateTraceId producing different values, which can be deterministic in CI with mocked random. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent bf0ba37 commit c57247f

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

packages/opentelemetry/test/trace.test.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,16 +2169,20 @@ describe('startNewTrace', () => {
21692169
});
21702170

21712171
it('does not leak the new traceId to the outer scope', () => {
2172-
const outerPropagationContext = getCurrentScope().getPropagationContext();
2173-
const outerTraceId = outerPropagationContext.traceId;
2172+
const outerScope = getCurrentScope();
2173+
const outerTraceId = outerScope.getPropagationContext().traceId;
21742174

21752175
startNewTrace(() => {
2176-
const innerTraceId = getCurrentScope().getPropagationContext().traceId;
2177-
expect(innerTraceId).not.toBe(outerTraceId);
2176+
// Manually set a known traceId on the inner scope to verify it doesn't leak
2177+
getCurrentScope().setPropagationContext({
2178+
traceId: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
2179+
sampleRand: 0.5,
2180+
});
21782181
});
21792182

2180-
const afterTraceId = getCurrentScope().getPropagationContext().traceId;
2183+
const afterTraceId = outerScope.getPropagationContext().traceId;
21812184
expect(afterTraceId).toBe(outerTraceId);
2185+
expect(afterTraceId).not.toBe('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
21822186
});
21832187
});
21842188

0 commit comments

Comments
 (0)