@@ -45,3 +45,46 @@ test('Records exceptions happening in middleware', async ({ request }) => {
4545
4646 expect ( await errorEventPromise ) . toBeDefined ( ) ;
4747} ) ;
48+
49+ test ( 'Should trace outgoing fetch requests inside middleware and create breadcrumbs for it' , async ( { request } ) => {
50+ const middlewareTransactionPromise = waitForTransaction ( 'nextjs-13-app-dir' , async transactionEvent => {
51+ return (
52+ transactionEvent ?. transaction === 'middleware' &&
53+ ! ! transactionEvent . spans ?. find ( span => span . op === 'http.client' )
54+ ) ;
55+ } ) ;
56+
57+ request . get ( '/api/endpoint-behind-middleware' , { headers : { 'x-should-make-request' : '1' } } ) . catch ( ( ) => {
58+ // Noop
59+ } ) ;
60+
61+ const middlewareTransaction = await middlewareTransactionPromise ;
62+
63+ expect ( middlewareTransaction . spans ) . toEqual (
64+ expect . arrayContaining ( [
65+ {
66+ data : { 'http.method' : 'GET' , 'http.response.status_code' : 200 , type : 'fetch' , url : 'http://localhost:3030/' } ,
67+ description : 'GET http://localhost:3030/' ,
68+ op : 'http.client' ,
69+ origin : 'auto.http.wintercg_fetch' ,
70+ parent_span_id : expect . any ( String ) ,
71+ span_id : expect . any ( String ) ,
72+ start_timestamp : expect . any ( Number ) ,
73+ status : 'ok' ,
74+ tags : { 'http.status_code' : '200' } ,
75+ timestamp : expect . any ( Number ) ,
76+ trace_id : expect . any ( String ) ,
77+ } ,
78+ ] ) ,
79+ ) ;
80+ expect ( middlewareTransaction . breadcrumbs ) . toEqual (
81+ expect . arrayContaining ( [
82+ {
83+ category : 'fetch' ,
84+ data : { __span : expect . any ( String ) , method : 'GET' , status_code : 200 , url : 'http://localhost:3030/' } ,
85+ timestamp : expect . any ( Number ) ,
86+ type : 'http' ,
87+ } ,
88+ ] ) ,
89+ ) ;
90+ } ) ;
0 commit comments