77 withIsolationScope ,
88} from '@sentry/core' ;
99import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core' ;
10- import { isString , logger , objectify , vercelWaitUntil } from '@sentry/utils' ;
10+ import { isString , logger , objectify } from '@sentry/utils' ;
1111import type { NextApiRequest } from 'next' ;
1212import type { AugmentedNextApiResponse , NextApiHandler } from './types' ;
1313import { flushSafelyWithTimeout } from './utils/responseEnd' ;
@@ -77,16 +77,6 @@ export function wrapApiHandlerWithSentry(apiHandler: NextApiHandler, parameteriz
7777 } ,
7878 } ,
7979 async span => {
80- // eslint-disable-next-line @typescript-eslint/unbound-method
81- res . end = new Proxy ( res . end , {
82- apply ( target , thisArg , argArray ) {
83- setHttpStatus ( span , res . statusCode ) ;
84- span . end ( ) ;
85- vercelWaitUntil ( flushSafelyWithTimeout ( ) ) ;
86- return target . apply ( thisArg , argArray ) ;
87- } ,
88- } ) ;
89-
9080 try {
9181 return await wrappingTarget . apply ( thisArg , args ) ;
9282 } catch ( e ) {
@@ -110,7 +100,9 @@ export function wrapApiHandlerWithSentry(apiHandler: NextApiHandler, parameteriz
110100 setHttpStatus ( span , 500 ) ;
111101 span . end ( ) ;
112102
113- vercelWaitUntil ( flushSafelyWithTimeout ( ) ) ;
103+ // we need to await the flush here to ensure that the error is captured
104+ // as the runtime freezes as soon as the error is thrown below
105+ await flushSafelyWithTimeout ( ) ;
114106
115107 // We rethrow here so that nextjs can do with the error whatever it would normally do. (Sometimes "whatever it
116108 // would normally do" is to allow the error to bubble up to the global handlers - another reason we need to mark
0 commit comments