11import { expect , test } from '@playwright/test' ;
2- import { waitForError } from '@sentry-internal/test-utils' ;
2+ import { waitForError , waitForTransaction } from '@sentry-internal/test-utils' ;
33
44test . describe ( 'server-side errors' , ( ) => {
55 test ( 'captures SSR error' , async ( { page } ) => {
66 const errorEventPromise = waitForError ( 'astro-4' , errorEvent => {
77 return errorEvent ?. exception ?. values ?. [ 0 ] ?. value === "Cannot read properties of undefined (reading 'x')" ;
88 } ) ;
99
10+ const transactionEventPromise = waitForTransaction ( 'astro-4' , transactionEvent => {
11+ return transactionEvent . transaction === 'GET /ssr-error' ;
12+ } ) ;
13+
1014 await page . goto ( '/ssr-error' ) ;
1115
1216 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 ( ) ;
1330
1431 expect ( errorEvent ) . toMatchObject ( {
1532 contexts : {
@@ -20,8 +37,8 @@ test.describe('server-side errors', () => {
2037 os : expect . any ( Object ) ,
2138 runtime : expect . any ( Object ) ,
2239 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 ,
2542 } ,
2643 } ,
2744 environment : 'qa' ,
@@ -69,18 +86,50 @@ test.describe('server-side errors', () => {
6986 const errorEventPromise = waitForError ( 'astro-4' , errorEvent => {
7087 return errorEvent ?. exception ?. values ?. [ 0 ] ?. value === 'Endpoint Error' ;
7188 } ) ;
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+ } ) ;
7295
7396 await page . goto ( '/endpoint-error' ) ;
7497 await page . getByText ( 'Get Data' ) . click ( ) ;
7598
7699 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 ) ;
77126
78127 expect ( errorEvent ) . toMatchObject ( {
79128 contexts : {
80129 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 ,
84133 } ,
85134 } ,
86135 exception : {
0 commit comments