@@ -18,15 +18,24 @@ sentryTest('creates a new trace on each navigation', async ({ getLocalTestPath,
18
18
const navigationEvent1 = await getFirstSentryEnvelopeRequest < Event > ( page , `${ url } #foo` ) ;
19
19
const navigationEvent2 = await getFirstSentryEnvelopeRequest < Event > ( page , `${ url } #bar` ) ;
20
20
21
- expect ( navigationEvent1 . contexts ?. trace ?. op ) . toBe ( 'navigation' ) ;
22
- expect ( navigationEvent2 . contexts ?. trace ?. op ) . toBe ( 'navigation' ) ;
23
-
24
- const navigation1TraceId = navigationEvent1 . contexts ?. trace ?. trace_id ;
25
- const navigation2TraceId = navigationEvent2 . contexts ?. trace ?. trace_id ;
26
-
27
- expect ( navigation1TraceId ) . toMatch ( / ^ [ 0 - 9 a - f ] { 32 } $ / ) ;
28
- expect ( navigation2TraceId ) . toMatch ( / ^ [ 0 - 9 a - f ] { 32 } $ / ) ;
29
- expect ( navigation1TraceId ) . not . toEqual ( navigation2TraceId ) ;
21
+ const navigation1TraceContext = navigationEvent1 . contexts ?. trace ;
22
+ const navigation2TraceContext = navigationEvent2 . contexts ?. trace ;
23
+
24
+ expect ( navigation1TraceContext ) . toMatchObject ( {
25
+ op : 'navigation' ,
26
+ trace_id : expect . stringMatching ( / ^ [ 0 - 9 a - f ] { 32 } $ / ) ,
27
+ span_id : expect . stringMatching ( / ^ [ 0 - 9 a - f ] { 16 } $ / ) ,
28
+ } ) ;
29
+ expect ( navigation1TraceContext ) . not . toHaveProperty ( 'parent_span_id' ) ;
30
+
31
+ expect ( navigation2TraceContext ) . toMatchObject ( {
32
+ op : 'navigation' ,
33
+ trace_id : expect . stringMatching ( / ^ [ 0 - 9 a - f ] { 32 } $ / ) ,
34
+ span_id : expect . stringMatching ( / ^ [ 0 - 9 a - f ] { 16 } $ / ) ,
35
+ } ) ;
36
+ expect ( navigation2TraceContext ) . not . toHaveProperty ( 'parent_span_id' ) ;
37
+
38
+ expect ( navigation1TraceContext ?. trace_id ) . not . toEqual ( navigation2TraceContext ?. trace_id ) ;
30
39
} ) ;
31
40
32
41
sentryTest ( 'error after navigation has navigation traceId' , async ( { getLocalTestPath, page } ) => {
@@ -40,17 +49,24 @@ sentryTest('error after navigation has navigation traceId', async ({ getLocalTes
40
49
await getFirstSentryEnvelopeRequest < Event > ( page , url ) ;
41
50
42
51
const navigationEvent = await getFirstSentryEnvelopeRequest < Event > ( page , `${ url } #foo` ) ;
43
- expect ( navigationEvent . contexts ?. trace ?. op ) . toBe ( 'navigation' ) ;
52
+ const navigationTraceContext = navigationEvent . contexts ?. trace ;
44
53
45
- const navigationTraceId = navigationEvent . contexts ?. trace ?. trace_id ;
46
- expect ( navigationTraceId ) . toMatch ( / ^ [ 0 - 9 a - f ] { 32 } $ / ) ;
54
+ expect ( navigationTraceContext ) . toMatchObject ( {
55
+ op : 'navigation' ,
56
+ trace_id : expect . stringMatching ( / ^ [ 0 - 9 a - f ] { 32 } $ / ) ,
57
+ span_id : expect . stringMatching ( / ^ [ 0 - 9 a - f ] { 16 } $ / ) ,
58
+ } ) ;
59
+ expect ( navigationTraceContext ) . not . toHaveProperty ( 'parent_span_id' ) ;
47
60
48
61
const errorEventPromise = getFirstSentryEnvelopeRequest < Event > ( page ) ;
49
62
await page . locator ( '#errorBtn' ) . click ( ) ;
50
63
const errorEvent = await errorEventPromise ;
51
64
52
- const errorTraceId = errorEvent . contexts ?. trace ?. trace_id ;
53
- expect ( errorTraceId ) . toBe ( navigationTraceId ) ;
65
+ const errorTraceContext = errorEvent . contexts ?. trace ;
66
+ expect ( errorTraceContext ) . toEqual ( {
67
+ trace_id : navigationTraceContext ?. trace_id ,
68
+ span_id : expect . stringMatching ( / ^ [ 0 - 9 a - f ] { 16 } $ / ) ,
69
+ } ) ;
54
70
} ) ;
55
71
56
72
sentryTest ( 'error during navigation has new navigation traceId' , async ( { getLocalTestPath, page } ) => {
@@ -71,13 +87,20 @@ sentryTest('error during navigation has new navigation traceId', async ({ getLoc
71
87
const navigationEvent = events . find ( event => event . type === 'transaction' ) ;
72
88
const errorEvent = events . find ( event => ! event . type ) ;
73
89
74
- expect ( navigationEvent ?. contexts ?. trace ?. op ) . toBe ( 'navigation' ) ;
75
-
76
- const navigationTraceId = navigationEvent ?. contexts ?. trace ?. trace_id ;
77
- expect ( navigationTraceId ) . toMatch ( / ^ [ 0 - 9 a - f ] { 32 } $ / ) ;
78
-
79
- const errorTraceId = errorEvent ?. contexts ?. trace ?. trace_id ;
80
- expect ( errorTraceId ) . toBe ( navigationTraceId ) ;
90
+ const navigationTraceContext = navigationEvent ?. contexts ?. trace ;
91
+ expect ( navigationTraceContext ) . toMatchObject ( {
92
+ op : 'navigation' ,
93
+ trace_id : expect . stringMatching ( / ^ [ 0 - 9 a - f ] { 32 } $ / ) ,
94
+ span_id : expect . stringMatching ( / ^ [ 0 - 9 a - f ] { 16 } $ / ) ,
95
+ } ) ;
96
+ expect ( navigationTraceContext ) . not . toHaveProperty ( 'parent_span_id' ) ;
97
+
98
+ const errorTraceContext = errorEvent ?. contexts ?. trace ;
99
+ expect ( errorTraceContext ) . toMatchObject ( {
100
+ op : 'navigation' ,
101
+ trace_id : errorTraceContext ?. trace_id ,
102
+ span_id : expect . stringMatching ( / ^ [ 0 - 9 a - f ] { 16 } $ / ) ,
103
+ } ) ;
81
104
} ) ;
82
105
83
106
sentryTest (
@@ -93,17 +116,22 @@ sentryTest(
93
116
await getFirstSentryEnvelopeRequest < Event > ( page , url ) ;
94
117
95
118
const navigationEvent = await getFirstSentryEnvelopeRequest < Event > ( page , `${ url } #foo` ) ;
96
- expect ( navigationEvent . contexts ?. trace ?. op ) . toBe ( 'navigation' ) ;
97
119
98
- const navigationTraceId = navigationEvent . contexts ?. trace ?. trace_id ;
99
- expect ( navigationTraceId ) . toMatch ( / ^ [ 0 - 9 a - f ] { 32 } $ / ) ;
120
+ const navigationTraceContext = navigationEvent . contexts ?. trace ;
121
+ expect ( navigationTraceContext ) . toMatchObject ( {
122
+ op : 'navigation' ,
123
+ trace_id : expect . stringMatching ( / ^ [ 0 - 9 a - f ] { 32 } $ / ) ,
124
+ span_id : expect . stringMatching ( / ^ [ 0 - 9 a - f ] { 16 } $ / ) ,
125
+ } ) ;
126
+ expect ( navigationTraceContext ) . not . toHaveProperty ( 'parent_span_id' ) ;
100
127
101
128
const requestPromise = page . waitForRequest ( 'http://example.com/*' ) ;
102
129
await page . locator ( '#fetchBtn' ) . click ( ) ;
103
130
const request = await requestPromise ;
104
131
const headers = request . headers ( ) ;
105
132
106
133
// sampling decision is deferred b/c of no active span at the time of request
134
+ const navigationTraceId = navigationTraceContext ?. trace_id ;
107
135
expect ( headers [ 'sentry-trace' ] ) . toMatch ( new RegExp ( `^${ navigationTraceId } -[0-9a-f]{16}$` ) ) ;
108
136
expect ( headers [ 'baggage' ] ) . toEqual (
109
137
`sentry-environment=production,sentry-public_key=public,sentry-trace_id=${ navigationTraceId } ` ,
@@ -129,14 +157,90 @@ sentryTest(
129
157
await page . locator ( '#fetchBtn' ) . click ( ) ;
130
158
const [ navigationEvent , request ] = await Promise . all ( [ navigationEventPromise , requestPromise ] ) ;
131
159
132
- expect ( navigationEvent . contexts ?. trace ?. op ) . toBe ( 'navigation' ) ;
160
+ const navigationTraceContext = navigationEvent . contexts ?. trace ;
161
+ expect ( navigationTraceContext ) . toMatchObject ( {
162
+ op : 'navigation' ,
163
+ trace_id : expect . stringMatching ( / ^ [ 0 - 9 a - f ] { 32 } $ / ) ,
164
+ span_id : expect . stringMatching ( / ^ [ 0 - 9 a - f ] { 16 } $ / ) ,
165
+ } ) ;
166
+ expect ( navigationTraceContext ) . not . toHaveProperty ( 'parent_span_id' ) ;
167
+
168
+ const headers = request . headers ( ) ;
169
+
170
+ // sampling decision is propagated from active span sampling decision
171
+ const navigationTraceId = navigationTraceContext ?. trace_id ;
172
+ expect ( headers [ 'sentry-trace' ] ) . toMatch ( new RegExp ( `^${ navigationTraceId } -[0-9a-f]{16}-1$` ) ) ;
173
+ expect ( headers [ 'baggage' ] ) . toEqual (
174
+ `sentry-environment=production,sentry-public_key=public,sentry-trace_id=${ navigationTraceId } ,sentry-sample_rate=1,sentry-sampled=true` ,
175
+ ) ;
176
+ } ,
177
+ ) ;
178
+
179
+ sentryTest (
180
+ 'outgoing XHR request after navigation has navigation traceId in headers' ,
181
+ async ( { getLocalTestPath, page } ) => {
182
+ if ( shouldSkipTracingTest ( ) ) {
183
+ sentryTest . skip ( ) ;
184
+ }
185
+
186
+ const url = await getLocalTestPath ( { testDir : __dirname } ) ;
187
+
188
+ // ensure navigation transaction is finished
189
+ await getFirstSentryEnvelopeRequest < Event > ( page , url ) ;
190
+
191
+ const navigationEvent = await getFirstSentryEnvelopeRequest < Event > ( page , `${ url } #foo` ) ;
192
+
193
+ const navigationTraceContext = navigationEvent . contexts ?. trace ;
194
+ expect ( navigationTraceContext ) . toMatchObject ( {
195
+ op : 'navigation' ,
196
+ trace_id : expect . stringMatching ( / ^ [ 0 - 9 a - f ] { 32 } $ / ) ,
197
+ span_id : expect . stringMatching ( / ^ [ 0 - 9 a - f ] { 16 } $ / ) ,
198
+ } ) ;
199
+ expect ( navigationTraceContext ) . not . toHaveProperty ( 'parent_span_id' ) ;
200
+
201
+ const xhrPromise = page . waitForRequest ( 'http://example.com/*' ) ;
202
+ await page . locator ( '#xhrBtn' ) . click ( ) ;
203
+ const request = await xhrPromise ;
204
+ const headers = request . headers ( ) ;
205
+
206
+ // sampling decision is deferred b/c of no active span at the time of request
207
+ const navigationTraceId = navigationTraceContext ?. trace_id ;
208
+ expect ( headers [ 'sentry-trace' ] ) . toMatch ( new RegExp ( `^${ navigationTraceId } -[0-9a-f]{16}$` ) ) ;
209
+ expect ( headers [ 'baggage' ] ) . toEqual (
210
+ `sentry-environment=production,sentry-public_key=public,sentry-trace_id=${ navigationTraceId } ` ,
211
+ ) ;
212
+ } ,
213
+ ) ;
214
+
215
+ sentryTest (
216
+ 'outgoing XHR request during navigation has navigation traceId in headers' ,
217
+ async ( { getLocalTestPath, page } ) => {
218
+ if ( shouldSkipTracingTest ( ) ) {
219
+ sentryTest . skip ( ) ;
220
+ }
133
221
134
- const navigationTraceId = navigationEvent . contexts ?. trace ?. trace_id ;
135
- expect ( navigationTraceId ) . toMatch ( / ^ [ 0 - 9 a - f ] { 32 } $ / ) ;
222
+ const url = await getLocalTestPath ( { testDir : __dirname } ) ;
223
+
224
+ // ensure navigation transaction is finished
225
+ await getFirstSentryEnvelopeRequest < Event > ( page , url ) ;
226
+
227
+ const navigationEventPromise = getFirstSentryEnvelopeRequest < Event > ( page ) ;
228
+ const requestPromise = page . waitForRequest ( 'http://example.com/*' ) ;
229
+ await page . goto ( `${ url } #foo` ) ;
230
+ await page . locator ( '#xhrBtn' ) . click ( ) ;
231
+ const [ navigationEvent , request ] = await Promise . all ( [ navigationEventPromise , requestPromise ] ) ;
136
232
233
+ const navigationTraceContext = navigationEvent . contexts ?. trace ;
234
+ expect ( navigationTraceContext ) . toMatchObject ( {
235
+ op : 'navigation' ,
236
+ trace_id : expect . stringMatching ( / ^ [ 0 - 9 a - f ] { 32 } $ / ) ,
237
+ span_id : expect . stringMatching ( / ^ [ 0 - 9 a - f ] { 16 } $ / ) ,
238
+ } ) ;
239
+ expect ( navigationTraceContext ) . not . toHaveProperty ( 'parent_span_id' ) ;
137
240
const headers = request . headers ( ) ;
138
241
139
242
// sampling decision is propagated from active span sampling decision
243
+ const navigationTraceId = navigationTraceContext ?. trace_id ;
140
244
expect ( headers [ 'sentry-trace' ] ) . toMatch ( new RegExp ( `^${ navigationTraceId } -[0-9a-f]{16}-1$` ) ) ;
141
245
expect ( headers [ 'baggage' ] ) . toEqual (
142
246
`sentry-environment=production,sentry-public_key=public,sentry-trace_id=${ navigationTraceId } ,sentry-sample_rate=1,sentry-sampled=true` ,
0 commit comments