11import { expect , test } from '@playwright/test' ;
2- import { waitForError , waitForTransaction } from '@sentry-internal/test-utils' ;
2+ import { waitForError , collectStreamedSpansUntilSegment } from '@sentry-internal/test-utils' ;
33
44test ( 'Sends correct error event' , async ( { baseURL } ) => {
55 const errorEventPromise = waitForError ( 'node-express' , event => {
66 return ! event . type && event . exception ?. values ?. [ 0 ] ?. value === 'This is an exception with id 123' ;
77 } ) ;
88
9- const transactionEventPromise = waitForTransaction ( 'node-express' , event => {
10- return event . transaction === 'GET /test-exception/:id' ;
11- } ) ;
9+ const segmentEventPromise = collectStreamedSpansUntilSegment ( 'node-express' , 'GET /test-exception/:id' ) ;
1210
1311 await fetch ( `${ baseURL } /test-exception/123` ) ;
1412
1513 const errorEvent = await errorEventPromise ;
16- const transactionEvent = await transactionEventPromise ;
14+ const segmentEventSpans = await segmentEventPromise ;
15+ const segmentEvent = segmentEventSpans . find (
16+ segment => segment . is_segment && segment . name === 'GET /test-exception/:id' ,
17+ ) ! ;
1718
1819 expect ( errorEvent . exception ?. values ) . toHaveLength ( 1 ) ;
1920 const exception = errorEvent . exception ?. values ?. [ 0 ] ;
@@ -38,13 +39,18 @@ test('Sends correct error event', async ({ baseURL }) => {
3839 parent_span_id : expect . stringMatching ( / [ a - f 0 - 9 ] { 16 } / ) ,
3940 } ) ;
4041
41- // The error is attached to the same trace as the request transaction , and to a
42- // span that belongs to that transaction (its root span or one of its children) .
43- const transactionTrace = transactionEvent . contexts ?. trace ;
44- expect ( errorEvent . contexts ?. trace ?. trace_id ) . toBe ( transactionTrace ?. trace_id ) ;
42+ // The error is attached to the same trace as the request segment , and to a
43+ // span in that segment .
44+ const segmentTrace = segmentEvent ;
45+ expect ( errorEvent . contexts ?. trace ?. trace_id ) . toBe ( segmentTrace ?. trace_id ) ;
4546
46- const transactionSpanIds = [ transactionTrace ?. span_id , ...( transactionEvent . spans ?? [ ] ) . map ( span => span . span_id ) ] ;
47- expect ( transactionSpanIds ) . toContain ( errorEvent . contexts ?. trace ?. span_id ) ;
47+ const segmentSpanIds = [
48+ segmentTrace ?. span_id ,
49+ ...segmentEventSpans
50+ . filter ( span => ! span . is_segment && span . attributes [ 'sentry.segment.id' ] ?. value === segmentEvent . span_id )
51+ . map ( span => span . span_id ) ,
52+ ] ;
53+ expect ( segmentSpanIds ) . toContain ( errorEvent . contexts ?. trace ?. span_id ) ;
4854} ) ;
4955
5056test ( 'Should record caught exceptions with local variable' , async ( { baseURL } ) => {
0 commit comments