7
7
withIsolationScope ,
8
8
} from '@sentry/core' ;
9
9
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core' ;
10
- import { isString , logger , objectify , vercelWaitUntil } from '@sentry/utils' ;
10
+ import { isString , logger , objectify } from '@sentry/utils' ;
11
11
import type { NextApiRequest } from 'next' ;
12
12
import type { AugmentedNextApiResponse , NextApiHandler } from './types' ;
13
13
import { flushSafelyWithTimeout } from './utils/responseEnd' ;
@@ -77,16 +77,6 @@ export function wrapApiHandlerWithSentry(apiHandler: NextApiHandler, parameteriz
77
77
} ,
78
78
} ,
79
79
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
-
90
80
try {
91
81
return await wrappingTarget . apply ( thisArg , args ) ;
92
82
} catch ( e ) {
@@ -110,7 +100,9 @@ export function wrapApiHandlerWithSentry(apiHandler: NextApiHandler, parameteriz
110
100
setHttpStatus ( span , 500 ) ;
111
101
span . end ( ) ;
112
102
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 ( ) ;
114
106
115
107
// We rethrow here so that nextjs can do with the error whatever it would normally do. (Sometimes "whatever it
116
108
// would normally do" is to allow the error to bubble up to the global handlers - another reason we need to mark
0 commit comments