@@ -41,11 +41,74 @@ sentryTest('error after navigation has navigation traceId', async ({ getLocalTes
41
41
const navigationTraceId = navigationEvent1 . contexts ?. trace ?. trace_id ;
42
42
expect ( navigationTraceId ) . toMatch ( / ^ [ 0 - 9 a - f ] { 32 } $ / ) ;
43
43
44
- const [ , errorEvent ] = await Promise . all ( [
45
- page . locator ( '#errorBtn' ) . click ( ) ,
46
- getFirstSentryEnvelopeRequest < Event > ( page ) ,
47
- ] ) ;
44
+ const errorEventPromise = getFirstSentryEnvelopeRequest < Event > ( page ) ;
45
+ await page . locator ( '#errorBtn' ) . click ( ) ;
46
+ const errorEvent = await errorEventPromise ;
48
47
49
48
const errorTraceId = errorEvent . contexts ?. trace ?. trace_id ;
50
49
expect ( errorTraceId ) . toBe ( navigationTraceId ) ;
51
50
} ) ;
51
+
52
+ sentryTest (
53
+ 'outgoing fetch request after navigation has navigation traceId in headers' ,
54
+ async ( { getLocalTestPath, page } ) => {
55
+ if ( shouldSkipTracingTest ( ) ) {
56
+ sentryTest . skip ( ) ;
57
+ }
58
+
59
+ const url = await getLocalTestPath ( { testDir : __dirname } ) ;
60
+
61
+ // ensure navigation transaction is finished
62
+ await getFirstSentryEnvelopeRequest < Event > ( page , url ) ;
63
+
64
+ const navigationEvent = await getFirstSentryEnvelopeRequest < Event > ( page , `${ url } #foo` ) ;
65
+ expect ( navigationEvent . contexts ?. trace ?. op ) . toBe ( 'navigation' ) ;
66
+
67
+ const navigationTraceId = navigationEvent . contexts ?. trace ?. trace_id ;
68
+ expect ( navigationTraceId ) . toMatch ( / ^ [ 0 - 9 a - f ] { 32 } $ / ) ;
69
+
70
+ const requestPromise = page . waitForRequest ( 'http://example.com/*' ) ;
71
+ await page . locator ( '#fetchBtn' ) . click ( ) ;
72
+ const request = await requestPromise ;
73
+ const headers = request . headers ( ) ;
74
+
75
+ // sampling decision is deferred b/c of no active span at the time of request
76
+ expect ( headers [ 'sentry-trace' ] ) . toMatch ( new RegExp ( `^${ navigationTraceId } -[0-9a-f]{16}$` ) ) ;
77
+ expect ( headers [ 'baggage' ] ) . toEqual (
78
+ `sentry-environment=production,sentry-public_key=public,sentry-trace_id=${ navigationTraceId } ` ,
79
+ ) ;
80
+ } ,
81
+ ) ;
82
+
83
+ sentryTest (
84
+ 'outgoing fetch request during navigation has navigation traceId in headers' ,
85
+ async ( { getLocalTestPath, page } ) => {
86
+ if ( shouldSkipTracingTest ( ) ) {
87
+ sentryTest . skip ( ) ;
88
+ }
89
+
90
+ const url = await getLocalTestPath ( { testDir : __dirname } ) ;
91
+
92
+ // ensure navigation transaction is finished
93
+ await getFirstSentryEnvelopeRequest < Event > ( page , url ) ;
94
+
95
+ const navigationEventPromise = getFirstSentryEnvelopeRequest < Event > ( page ) ;
96
+ const requestPromise = page . waitForRequest ( 'http://example.com/*' ) ;
97
+ await page . goto ( `${ url } #foo` ) ;
98
+ await page . locator ( '#fetchBtn' ) . click ( ) ;
99
+ const [ navigationEvent , request ] = await Promise . all ( [ navigationEventPromise , requestPromise ] ) ;
100
+
101
+ expect ( navigationEvent . contexts ?. trace ?. op ) . toBe ( 'navigation' ) ;
102
+
103
+ const navigationTraceId = navigationEvent . contexts ?. trace ?. trace_id ;
104
+ expect ( navigationTraceId ) . toMatch ( / ^ [ 0 - 9 a - f ] { 32 } $ / ) ;
105
+
106
+ const headers = request . headers ( ) ;
107
+
108
+ // sampling decision is propagated from active span sampling decision
109
+ expect ( headers [ 'sentry-trace' ] ) . toMatch ( new RegExp ( `^${ navigationTraceId } -[0-9a-f]{16}-1$` ) ) ;
110
+ expect ( headers [ 'baggage' ] ) . toEqual (
111
+ `sentry-environment=production,sentry-public_key=public,sentry-trace_id=${ navigationTraceId } ,sentry-sample_rate=1,sentry-sampled=true` ,
112
+ ) ;
113
+ } ,
114
+ ) ;
0 commit comments