11import { expect , test } from '@playwright/test' ;
22import { waitForError , waitForTransaction } from '@sentry-internal/test-utils' ;
3+ import { isNext13 } from './nextjsVersion' ;
34
45test ( 'Sends a transaction for a request to app router' , async ( { page } ) => {
56 const serverComponentTransactionPromise = waitForTransaction ( 'nextjs-app-dir' , transactionEvent => {
@@ -70,19 +71,29 @@ test('Should set a "not_found" status on a server component span when notFound()
7071
7172 const transactionEvent = await serverComponentTransactionPromise ;
7273
73- // Transaction should have status ok, because the http status is ok, but the server component span should be not_found
74+ // Transaction should have status ok, because the http status is ok, but the render component span should be not_found
7475 expect ( transactionEvent . contexts ?. trace ?. status ) . toBe ( 'ok' ) ;
7576 expect ( transactionEvent . spans ) . toContainEqual (
7677 expect . objectContaining ( {
77- description : 'Page Server Component (/server-component/not-found)' ,
78- op : 'function.nextjs' ,
78+ description : 'render route (app) /server-component/not-found' ,
7979 status : 'not_found' ,
80- data : expect . objectContaining ( {
81- 'sentry.nextjs.ssr.function.type' : 'Page' ,
82- 'sentry.nextjs.ssr.function.route' : '/server-component/not-found' ,
83- } ) ,
8480 } ) ,
8581 ) ;
82+
83+ // Next.js 13 has limited OTEL support for server components, so we don't expect to see the following span
84+ if ( ! isNext13 ) {
85+ // Page server component span should have the right name and attributes
86+ expect ( transactionEvent . spans ) . toContainEqual (
87+ expect . objectContaining ( {
88+ description : 'resolve page server component "/server-component/not-found"' ,
89+ op : 'function.nextjs' ,
90+ data : expect . objectContaining ( {
91+ 'sentry.nextjs.ssr.function.type' : 'Page' ,
92+ 'sentry.nextjs.ssr.function.route' : '/server-component/not-found' ,
93+ } ) ,
94+ } ) ,
95+ ) ;
96+ }
8697} ) ;
8798
8899test ( 'Should capture an error and transaction for a app router page' , async ( { page } ) => {
@@ -102,20 +113,30 @@ test('Should capture an error and transaction for a app router page', async ({ p
102113 // Error event should have the right transaction name
103114 expect ( errorEvent . transaction ) . toBe ( `Page Server Component (/server-component/faulty)` ) ;
104115
105- // Transaction should have status ok, because the http status is ok, but the server component span should be internal_error
116+ // Transaction should have status ok, because the http status is ok, but the render component span should be internal_error
106117 expect ( transactionEvent . contexts ?. trace ?. status ) . toBe ( 'ok' ) ;
107118 expect ( transactionEvent . spans ) . toContainEqual (
108119 expect . objectContaining ( {
109- description : 'Page Server Component (/server-component/faulty)' ,
110- op : 'function.nextjs' ,
120+ description : 'render route (app) /server-component/faulty' ,
111121 status : 'internal_error' ,
112- data : expect . objectContaining ( {
113- 'sentry.nextjs.ssr.function.type' : 'Page' ,
114- 'sentry.nextjs.ssr.function.route' : '/server-component/faulty' ,
115- } ) ,
116122 } ) ,
117123 ) ;
118124
125+ // Next.js 13 has limited OTEL support for server components, so we don't expect to see the following span
126+ if ( ! isNext13 ) {
127+ // The page server component span should have the right name and attributes
128+ expect ( transactionEvent . spans ) . toContainEqual (
129+ expect . objectContaining ( {
130+ description : 'resolve page server component "/server-component/faulty"' ,
131+ op : 'function.nextjs' ,
132+ data : expect . objectContaining ( {
133+ 'sentry.nextjs.ssr.function.type' : 'Page' ,
134+ 'sentry.nextjs.ssr.function.route' : '/server-component/faulty' ,
135+ } ) ,
136+ } ) ,
137+ ) ;
138+ }
139+
119140 expect ( errorEvent . tags ?. [ 'my-isolated-tag' ] ) . toBe ( true ) ;
120141 expect ( errorEvent . tags ?. [ 'my-global-scope-isolated-tag' ] ) . not . toBeDefined ( ) ;
121142 expect ( transactionEvent . tags ?. [ 'my-isolated-tag' ] ) . toBe ( true ) ;
0 commit comments