1
1
import { expect , test } from '@playwright/test' ;
2
- import { waitForError } from '@sentry-internal/test-utils' ;
2
+ import { waitForError , waitForTransaction } from '@sentry-internal/test-utils' ;
3
3
4
4
test . describe ( 'server-side errors' , ( ) => {
5
5
test ( 'captures SSR error' , async ( { page } ) => {
6
6
const errorEventPromise = waitForError ( 'astro-4' , errorEvent => {
7
7
return errorEvent ?. exception ?. values ?. [ 0 ] ?. value === "Cannot read properties of undefined (reading 'x')" ;
8
8
} ) ;
9
9
10
+ const transactionEventPromise = waitForTransaction ( 'astro-4' , transactionEvent => {
11
+ return transactionEvent . transaction === 'GET /ssr-error' ;
12
+ } ) ;
13
+
10
14
await page . goto ( '/ssr-error' ) ;
11
15
12
16
const errorEvent = await errorEventPromise ;
17
+ const transactionEvent = await transactionEventPromise ;
18
+
19
+ expect ( transactionEvent ) . toMatchObject ( {
20
+ transaction : 'GET /ssr-error' ,
21
+ spans : [ ] ,
22
+ } ) ;
23
+
24
+ const traceId = transactionEvent . contexts ?. trace ?. trace_id ;
25
+ const spanId = transactionEvent . contexts ?. trace ?. span_id ;
26
+
27
+ expect ( traceId ) . toMatch ( / [ a - f 0 - 9 ] { 32 } / ) ;
28
+ expect ( spanId ) . toMatch ( / [ a - f 0 - 9 ] { 16 } / ) ;
29
+ expect ( transactionEvent . contexts ?. trace ?. parent_span_id ) . toBeUndefined ( ) ;
13
30
14
31
expect ( errorEvent ) . toMatchObject ( {
15
32
contexts : {
@@ -20,8 +37,8 @@ test.describe('server-side errors', () => {
20
37
os : expect . any ( Object ) ,
21
38
runtime : expect . any ( Object ) ,
22
39
trace : {
23
- span_id : '' , //TODO: This is a bug! We should expect.stringMatching(/[a-f0-9]{16}/) instead of ''
24
- trace_id : expect . stringMatching ( / [ a - f 0 - 9 ] { 32 } / ) ,
40
+ span_id : spanId ,
41
+ trace_id : traceId ,
25
42
} ,
26
43
} ,
27
44
environment : 'qa' ,
@@ -69,18 +86,50 @@ test.describe('server-side errors', () => {
69
86
const errorEventPromise = waitForError ( 'astro-4' , errorEvent => {
70
87
return errorEvent ?. exception ?. values ?. [ 0 ] ?. value === 'Endpoint Error' ;
71
88
} ) ;
89
+ const transactionEventApiPromise = waitForTransaction ( 'astro-4' , transactionEvent => {
90
+ return transactionEvent . transaction === 'GET /endpoint-error/api' ;
91
+ } ) ;
92
+ const transactionEventEndpointPromise = waitForTransaction ( 'astro-4' , transactionEvent => {
93
+ return transactionEvent . transaction === 'GET /endpoint-error' ;
94
+ } ) ;
72
95
73
96
await page . goto ( '/endpoint-error' ) ;
74
97
await page . getByText ( 'Get Data' ) . click ( ) ;
75
98
76
99
const errorEvent = await errorEventPromise ;
100
+ const transactionEventApi = await transactionEventApiPromise ;
101
+ const transactionEventEndpoint = await transactionEventEndpointPromise ;
102
+
103
+ expect ( transactionEventEndpoint ) . toMatchObject ( {
104
+ transaction : 'GET /endpoint-error' ,
105
+ spans : [ ] ,
106
+ } ) ;
107
+
108
+ const traceId = transactionEventEndpoint . contexts ?. trace ?. trace_id ;
109
+ const endpointSpanId = transactionEventApi . contexts ?. trace ?. span_id ;
110
+
111
+ expect ( traceId ) . toMatch ( / [ a - f 0 - 9 ] { 32 } / ) ;
112
+ expect ( endpointSpanId ) . toMatch ( / [ a - f 0 - 9 ] { 16 } / ) ;
113
+
114
+ expect ( transactionEventApi ) . toMatchObject ( {
115
+ transaction : 'GET /endpoint-error/api' ,
116
+ spans : [ ] ,
117
+ } ) ;
118
+
119
+ const spanId = transactionEventApi . contexts ?. trace ?. span_id ;
120
+ const parentSpanId = transactionEventApi . contexts ?. trace ?. parent_span_id ;
121
+
122
+ expect ( spanId ) . toMatch ( / [ a - f 0 - 9 ] { 16 } / ) ;
123
+ // TODO: This is incorrect, for whatever reason, it should be the endpointSpanId ideally
124
+ expect ( parentSpanId ) . toMatch ( / [ a - f 0 - 9 ] { 16 } / ) ;
125
+ expect ( parentSpanId ) . not . toEqual ( endpointSpanId ) ;
77
126
78
127
expect ( errorEvent ) . toMatchObject ( {
79
128
contexts : {
80
129
trace : {
81
- parent_span_id : expect . stringMatching ( / [ a - f 0 - 9 ] { 16 } / ) ,
82
- span_id : expect . stringMatching ( / [ a - f 0 - 9 ] { 16 } / ) ,
83
- trace_id : expect . stringMatching ( / [ a - f 0 - 9 ] { 32 } / ) ,
130
+ parent_span_id : parentSpanId ,
131
+ span_id : spanId ,
132
+ trace_id : traceId ,
84
133
} ,
85
134
} ,
86
135
exception : {
0 commit comments