Commit b9fcb1f
fix(test/utils/tracing): disable OTel globals before re-registering in createInMemoryTracing
The previous form (commit 133d468) skipped `provider.register()` to
avoid "Attempted duplicate registration of API: trace" when another
test in the same shard had already loaded `~/v3/tracer.server.ts`
(which calls register() via its `singleton("opentelemetry", …)`).
That fix went too far: tests like `sentryTraceContext.server.test.ts`
exercise OTel's *global* API (`trace.getActiveSpan()` via
`getActiveTraceIds`), which requires a registered global context
manager. Without register(), `trace.getActiveSpan()` returned
undefined — 6/9 assertions in that file flipped red on shard 1 of
the latest CI run.
Webapp's vitest config uses `pool: "forks"` with
`--no-file-parallelism`, so all test files in a shard share one
process. globalThis persists across files even though vitest clears
the module cache between them. OTel's `setGlobal*` no-ops (logs an
error, returns false) when a global is already set — so the second
caller's register() is a no-op, leaving the globals pointed at the
first caller's provider.
Fix: call `trace.disable(); context.disable(); propagation.disable();`
*before* `provider.register()`. The disables clear any previously-set
globals (whether from `tracer.server.ts`'s singleton or a prior
createInMemoryTracing call), so the test's provider always wins for
both span recording (via SimpleSpanProcessor) AND the global API.
Each createInMemoryTracing call rotates the globals; no leakage to
the next test file.
Verified locally: `pnpm vitest run test/sentryTraceContext.server.test.ts`
9/9 pass. Running it alongside test/engine/triggerTask.test.ts (which
loads tracer.server.ts) reaches the test-setup phase normally —
no more module-load OTel collision.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent c70d755 commit b9fcb1f
1 file changed
Lines changed: 25 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
19 | 15 | | |
20 | | - | |
21 | | - | |
22 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
23 | 36 | | |
24 | 37 | | |
25 | 38 | | |
26 | 39 | | |
| 40 | + | |
27 | 41 | | |
28 | 42 | | |
29 | 43 | | |
| |||
0 commit comments