-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathtest.ts
More file actions
64 lines (57 loc) · 2.56 KB
/
test.ts
File metadata and controls
64 lines (57 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { expect, it } from 'vitest';
import { createRunner } from '../../../runner';
// Regression test for https://github.com/getsentry/sentry-javascript/issues/20030
// When a Durable Object method calls Sentry.startSpan multiple times, those spans
// must appear as children of the DO transaction. The first invocation always worked;
// the second invocation on the same DO instance previously lost its child spans
// because the client was disposed after the first call.
it('sends child spans on repeated Durable Object calls', async ({ signal }) => {
function assertDoWorkEnvelope(envelope: unknown): void {
const transactionEvent = (envelope as any)[1]?.[0]?.[1];
expect(transactionEvent).toEqual(
expect.objectContaining({
transaction: 'doWork',
contexts: expect.objectContaining({
trace: expect.objectContaining({
op: 'rpc',
origin: 'auto.faas.cloudflare.durable_object',
}),
}),
}),
);
// All 5 child spans should be present
expect(transactionEvent.spans).toHaveLength(5);
expect(transactionEvent.spans).toEqual(
expect.arrayContaining([
expect.objectContaining({ description: 'task-1', op: 'task' }),
expect.objectContaining({ description: 'task-2', op: 'task' }),
expect.objectContaining({ description: 'task-3', op: 'task' }),
expect.objectContaining({ description: 'task-4', op: 'task' }),
expect.objectContaining({ description: 'task-5', op: 'task' }),
]),
);
// All child spans share the root trace_id
const rootTraceId = transactionEvent.contexts?.trace?.trace_id;
expect(rootTraceId).toBeDefined();
for (const span of transactionEvent.spans) {
expect(span.trace_id).toBe(rootTraceId);
}
}
// Expect 5 transaction envelopes — one per call.
const runner = createRunner(__dirname).expectN(5, assertDoWorkEnvelope).start(signal);
// Small delay between requests to allow waitUntil to process in wrangler dev.
// This is needed because wrangler dev may not guarantee waitUntil completion
// the same way production Cloudflare does. Without this delay, the last
// envelope's HTTP request may not complete before the test moves on.
const delay = () => new Promise(resolve => setTimeout(resolve, 50));
await runner.makeRequest('get', '/');
await delay();
await runner.makeRequest('get', '/');
await delay();
await runner.makeRequest('get', '/');
await delay();
await runner.makeRequest('get', '/');
await delay();
await runner.makeRequest('get', '/');
await runner.completed();
});