File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed
dev-packages/node-integration-tests/suites/public-api/withMonitor Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments