11import { expect , test } from '@playwright/test' ;
2- import { waitForTransaction } from '@sentry-internal/test-utils' ;
2+ import { collectStreamedSpans , getSpanOp } from '@sentry-internal/test-utils' ;
33
44/**
55 * This must be the only test in here.
@@ -10,24 +10,43 @@ import { waitForTransaction } from '@sentry-internal/test-utils';
1010 * and masks bugs in our instrumentation - causing this test to pass when it
1111 * should fail.
1212 */
13- test ( 'Worker and Durable Object both send transactions when worker calls DO' , async ( { baseURL } ) => {
14- const workerTransactionPromise = waitForTransaction ( 'cloudflare-local-workers' , event => {
15- return event . transaction === 'GET /pass-to-object/storage/get' && event . contexts ?. trace ?. op === 'http.server' ;
16- } ) ;
17-
18- const doTransactionPromise = waitForTransaction ( 'cloudflare-local-workers' , event => {
19- return event . transaction === 'GET /storage/get' && event . contexts ?. trace ?. op === 'http.server' ;
13+ test ( 'Worker and Durable Object both send segment spans when worker calls DO' , async ( { baseURL } ) => {
14+ // With span streaming, URL-sourced `http.server` spans are named by method only, so the worker
15+ // and the Durable Object segment can only be told apart by `url.path`.
16+ const spansPromise = collectStreamedSpans ( 'cloudflare-local-workers' , spans => {
17+ return (
18+ spans . some (
19+ span =>
20+ getSpanOp ( span ) === 'http.server' &&
21+ span . is_segment &&
22+ span . attributes [ 'url.path' ] ?. value === '/pass-to-object/storage/get' ,
23+ ) &&
24+ spans . some (
25+ span =>
26+ getSpanOp ( span ) === 'http.server' && span . is_segment && span . attributes [ 'url.path' ] ?. value === '/storage/get' ,
27+ )
28+ ) ;
2029 } ) ;
2130
2231 const response = await fetch ( `${ baseURL } /pass-to-object/storage/get` ) ;
2332 expect ( response . status ) . toBe ( 200 ) ;
2433
25- const [ workerTransaction , doTransaction ] = await Promise . all ( [ workerTransactionPromise , doTransactionPromise ] ) ;
34+ const spans = await spansPromise ;
35+ const workerSpan = spans . find (
36+ span =>
37+ getSpanOp ( span ) === 'http.server' &&
38+ span . is_segment &&
39+ span . attributes [ 'url.path' ] ?. value === '/pass-to-object/storage/get' ,
40+ ) ! ;
41+ const doSpan = spans . find (
42+ span =>
43+ getSpanOp ( span ) === 'http.server' && span . is_segment && span . attributes [ 'url.path' ] ?. value === '/storage/get' ,
44+ ) ! ;
2645
27- expect ( workerTransaction . transaction ) . toBe ( 'GET /pass-to-object/storage/get ' ) ;
28- expect ( workerTransaction . contexts ?. trace ?. op ) . toBe ( 'http.server ' ) ;
46+ expect ( workerSpan . name ) . toBe ( 'GET' ) ;
47+ expect ( workerSpan . attributes [ 'sentry.segment.name.source' ] ?. value ) . toBe ( 'url ' ) ;
2948
30- expect ( doTransaction . transaction ) . toBe ( 'GET /storage/get ' ) ;
31- expect ( doTransaction . contexts ?. trace ?. op ) . toBe ( 'http.server ' ) ;
32- expect ( doTransaction . spans ? .some ( span => span . op === 'db' ) ) . toBe ( true ) ;
49+ expect ( doSpan . name ) . toBe ( 'GET' ) ;
50+ expect ( doSpan . attributes [ 'sentry.segment.name.source' ] ?. value ) . toBe ( 'url ' ) ;
51+ expect ( spans . some ( span => getSpanOp ( span ) === 'db' && span . parent_span_id === doSpan . span_id ) ) . toBe ( true ) ;
3352} ) ;
0 commit comments