@@ -2,48 +2,51 @@ import { expect } from '@playwright/test';
22import { sentryTest } from '../../../../utils/fixtures' ;
33import { envelopeRequestParser , shouldSkipTracingTest , waitForTransactionRequest } from '../../../../utils/helpers' ;
44
5- sentryTest ( 'nested calls to setSpanActive still parent to root span by default' , async ( { getLocalTestUrl, page } ) => {
6- if ( shouldSkipTracingTest ( ) ) {
7- sentryTest . skip ( ) ;
8- }
9-
10- const req = waitForTransactionRequest ( page , e => e . transaction === 'checkout-flow' ) ;
11- const postCheckoutReq = waitForTransactionRequest ( page , e => e . transaction === 'post-checkout' ) ;
12-
13- const url = await getLocalTestUrl ( { testDir : __dirname } ) ;
14- await page . goto ( url ) ;
15-
16- const checkoutEvent = envelopeRequestParser ( await req ) ;
17- const postCheckoutEvent = envelopeRequestParser ( await postCheckoutReq ) ;
18-
19- const checkoutSpanId = checkoutEvent . contexts ?. trace ?. span_id ;
20- const postCheckoutSpanId = postCheckoutEvent . contexts ?. trace ?. span_id ;
21-
22- expect ( checkoutSpanId ) . toMatch ( / [ a - f 0 - 9 ] { 16 } / ) ;
23- expect ( postCheckoutSpanId ) . toMatch ( / [ a - f 0 - 9 ] { 16 } / ) ;
24-
25- expect ( checkoutEvent . spans ) . toHaveLength ( 4 ) ;
26- expect ( postCheckoutEvent . spans ) . toHaveLength ( 1 ) ;
27-
28- const checkoutStep1 = checkoutEvent . spans ?. find ( s => s . description === 'checkout-step-1' ) ;
29- const checkoutStep2 = checkoutEvent . spans ?. find ( s => s . description === 'checkout-step-2' ) ;
30- const checkoutStep21 = checkoutEvent . spans ?. find ( s => s . description === 'checkout-step-2-1' ) ;
31- const checkoutStep3 = checkoutEvent . spans ?. find ( s => s . description === 'checkout-step-3' ) ;
32-
33- expect ( checkoutStep1 ) . toBeDefined ( ) ;
34- expect ( checkoutStep2 ) . toBeDefined ( ) ;
35- expect ( checkoutStep21 ) . toBeDefined ( ) ;
36- expect ( checkoutStep3 ) . toBeDefined ( ) ;
37-
38- expect ( checkoutStep1 ?. parent_span_id ) . toBe ( checkoutSpanId ) ;
39- expect ( checkoutStep2 ?. parent_span_id ) . toBe ( checkoutSpanId ) ;
40- expect ( checkoutStep3 ?. parent_span_id ) . toBe ( checkoutSpanId ) ;
41-
42- // despite 2-1 being called within 2 AND setting 2 as active span, it's still parented to the
43- // root span due to this being default behaviour in browser environments
44- expect ( checkoutStep21 ?. parent_span_id ) . toBe ( checkoutSpanId ) ;
45-
46- const postCheckoutStep1 = postCheckoutEvent . spans ?. find ( s => s . description === 'post-checkout-1' ) ;
47- expect ( postCheckoutStep1 ) . toBeDefined ( ) ;
48- expect ( postCheckoutStep1 ?. parent_span_id ) . toBe ( postCheckoutSpanId ) ;
49- } ) ;
5+ sentryTest (
6+ 'nested calls to setActiveSpanInBrowser still parent to root span by default' ,
7+ async ( { getLocalTestUrl, page } ) => {
8+ if ( shouldSkipTracingTest ( ) ) {
9+ sentryTest . skip ( ) ;
10+ }
11+
12+ const req = waitForTransactionRequest ( page , e => e . transaction === 'checkout-flow' ) ;
13+ const postCheckoutReq = waitForTransactionRequest ( page , e => e . transaction === 'post-checkout' ) ;
14+
15+ const url = await getLocalTestUrl ( { testDir : __dirname } ) ;
16+ await page . goto ( url ) ;
17+
18+ const checkoutEvent = envelopeRequestParser ( await req ) ;
19+ const postCheckoutEvent = envelopeRequestParser ( await postCheckoutReq ) ;
20+
21+ const checkoutSpanId = checkoutEvent . contexts ?. trace ?. span_id ;
22+ const postCheckoutSpanId = postCheckoutEvent . contexts ?. trace ?. span_id ;
23+
24+ expect ( checkoutSpanId ) . toMatch ( / [ a - f 0 - 9 ] { 16 } / ) ;
25+ expect ( postCheckoutSpanId ) . toMatch ( / [ a - f 0 - 9 ] { 16 } / ) ;
26+
27+ expect ( checkoutEvent . spans ) . toHaveLength ( 4 ) ;
28+ expect ( postCheckoutEvent . spans ) . toHaveLength ( 1 ) ;
29+
30+ const checkoutStep1 = checkoutEvent . spans ?. find ( s => s . description === 'checkout-step-1' ) ;
31+ const checkoutStep2 = checkoutEvent . spans ?. find ( s => s . description === 'checkout-step-2' ) ;
32+ const checkoutStep21 = checkoutEvent . spans ?. find ( s => s . description === 'checkout-step-2-1' ) ;
33+ const checkoutStep3 = checkoutEvent . spans ?. find ( s => s . description === 'checkout-step-3' ) ;
34+
35+ expect ( checkoutStep1 ) . toBeDefined ( ) ;
36+ expect ( checkoutStep2 ) . toBeDefined ( ) ;
37+ expect ( checkoutStep21 ) . toBeDefined ( ) ;
38+ expect ( checkoutStep3 ) . toBeDefined ( ) ;
39+
40+ expect ( checkoutStep1 ?. parent_span_id ) . toBe ( checkoutSpanId ) ;
41+ expect ( checkoutStep2 ?. parent_span_id ) . toBe ( checkoutSpanId ) ;
42+ expect ( checkoutStep3 ?. parent_span_id ) . toBe ( checkoutSpanId ) ;
43+
44+ // despite 2-1 being called within 2 AND setting 2 as active span, it's still parented to the
45+ // root span due to this being default behaviour in browser environments
46+ expect ( checkoutStep21 ?. parent_span_id ) . toBe ( checkoutSpanId ) ;
47+
48+ const postCheckoutStep1 = postCheckoutEvent . spans ?. find ( s => s . description === 'post-checkout-1' ) ;
49+ expect ( postCheckoutStep1 ) . toBeDefined ( ) ;
50+ expect ( postCheckoutStep1 ?. parent_span_id ) . toBe ( postCheckoutSpanId ) ;
51+ } ,
52+ ) ;
0 commit comments