File tree Expand file tree Collapse file tree 3 files changed +78
-0
lines changed
dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/async-spans Expand file tree Collapse file tree 3 files changed +78
-0
lines changed Original file line number Diff line number Diff line change 1+ import * as Sentry from '@sentry/browser' ;
2+
3+ window . Sentry = Sentry ;
4+
5+ Sentry . init ( {
6+ dsn :
'https://[email protected] /1337' , 7+ integrations : [ Sentry . browserTracingIntegration ( ) ] ,
8+ tracesSampleRate : 1 ,
9+ } ) ;
Original file line number Diff line number Diff line change 1+ import { getActiveSpan , spanToJSON , startSpan } from '@sentry/browser' ;
2+
3+ const waitForSeconds = seconds => new Promise ( res => setTimeout ( res , seconds * 1000 ) ) ;
4+
5+ startSpan ( { name : 'span 1' } , async ( ) => {
6+ await waitForSeconds ( 1 ) ;
7+ window . firstWaitingSpan = spanToJSON ( getActiveSpan ( ) ) ;
8+ } ) ;
9+
10+ startSpan ( { name : 'span 2' } , async ( ) => {
11+ await waitForSeconds ( 2 ) ;
12+ window . secondWaitingSpan = spanToJSON ( getActiveSpan ( ) ) ;
13+ } ) ;
14+
15+ startSpan ( { name : 'span 3' } , async ( ) => {
16+ await waitForSeconds ( 0.5 ) ;
17+ window . thirdWaitingSpan = spanToJSON ( getActiveSpan ( ) ) ;
18+ } ) ;
19+
20+ /**
21+ * This is what happens here:
22+ * 1. span 1 starts
23+ * 2. span 2 starts
24+ * 3. span 3 starts (span 3 is active now)
25+ * 4. waiting time in span 3 is over and 'span 3' is stored in variable
26+ * 5. span 3 ends (2 is active now)
27+ * 6. waiting time in span 1 is over and 'span 2' is stored in variable
28+ * 7. span 2 ends (1 is active now)
29+ * 8. waiting time in span 2 is over and 'span 1' is stored in variable
30+ */
Original file line number Diff line number Diff line change 1+ import { expect } from '@playwright/test' ;
2+ import type { Event } from '@sentry/types' ;
3+ import { sentryTest } from '../../../../utils/fixtures' ;
4+ import { getFirstSentryEnvelopeRequest , shouldSkipTracingTest } from '../../../../utils/helpers' ;
5+
6+ type WindowWithSpan = Window & {
7+ firstWaitingSpan : any ;
8+ secondWaitingSpan : any ;
9+ thirdWaitingSpan : any ;
10+ } ;
11+
12+ sentryTest (
13+ 'async spans with different durations lead to unexpected behavior in browser (no "asynchronous context tracking")' ,
14+ async ( { getLocalTestPath, page } ) => {
15+ if ( shouldSkipTracingTest ( ) ) {
16+ sentryTest . skip ( ) ;
17+ }
18+
19+ const url = await getLocalTestPath ( { testDir : __dirname } ) ;
20+ await page . goto ( url ) ;
21+
22+ const envelope = await getFirstSentryEnvelopeRequest < Event > ( page ) ;
23+ expect ( envelope ) . toBeDefined ( ) ;
24+
25+ const firstWaitingSpanValue = await page . evaluate (
26+ ( ) => ( window as unknown as WindowWithSpan ) . firstWaitingSpan . description ,
27+ ) ;
28+ const secondWaitingSpanName = await page . evaluate (
29+ ( ) => ( window as unknown as WindowWithSpan ) . secondWaitingSpan . description ,
30+ ) ;
31+ const thirdWaitingSpanName = await page . evaluate (
32+ ( ) => ( window as unknown as WindowWithSpan ) . thirdWaitingSpan . description ,
33+ ) ;
34+
35+ expect ( firstWaitingSpanValue ) . toBe ( 'span 2' ) ;
36+ expect ( secondWaitingSpanName ) . toBe ( 'span 1' ) ;
37+ expect ( thirdWaitingSpanName ) . toBe ( 'span 3' ) ;
38+ } ,
39+ ) ;
You can’t perform that action at this time.
0 commit comments