Skip to content

Commit a16ae77

Browse files
committed
test: Add integration test for isolateTrace functionality
Add node integration test to verify that withMonitor calls with isolateTrace: true generate different trace IDs, confirming trace isolation works as expected.
1 parent e06ae30 commit a16ae77

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { withMonitor } from '@sentry/node';
2+
3+
export async function run(): Promise<void> {
4+
// First withMonitor call without isolateTrace (should share trace)
5+
await withMonitor('cron-job-1', async () => {
6+
// Simulate some work
7+
await new Promise<void>((resolve) => {
8+
setTimeout(() => {
9+
resolve();
10+
}, 100);
11+
});
12+
}, {
13+
schedule: { type: 'crontab', value: '* * * * *' }
14+
});
15+
16+
// Second withMonitor call with isolateTrace (should have different trace)
17+
await withMonitor('cron-job-2', async () => {
18+
// Simulate some work
19+
await new Promise<void>((resolve) => {
20+
setTimeout(() => {
21+
resolve();
22+
}, 100);
23+
});
24+
}, {
25+
schedule: { type: 'crontab', value: '* * * * *' },
26+
isolateTrace: true
27+
});
28+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { expect } from 'vitest';
2+
import type { Event, TransactionEvent } from '@sentry/types';
3+
4+
export async function testResults(events: Event[]): Promise<void> {
5+
// Get all transaction events (which represent traces)
6+
const transactionEvents = events.filter((event): event is TransactionEvent => event.type === 'transaction');
7+
8+
// Should have at least 2 transaction events (one for each withMonitor call)
9+
expect(transactionEvents.length).toBeGreaterThanOrEqual(2);
10+
11+
// Get trace IDs from the transactions
12+
const traceIds = transactionEvents.map(event => event.contexts?.trace?.trace_id).filter(Boolean);
13+
14+
// Should have at least 2 different trace IDs (verifying trace isolation)
15+
const uniqueTraceIds = [...new Set(traceIds)];
16+
expect(uniqueTraceIds.length).toBeGreaterThanOrEqual(2);
17+
18+
console.log('✅ Found traces with different trace IDs:', uniqueTraceIds);
19+
}

0 commit comments

Comments
 (0)