Skip to content

Commit f9df1b4

Browse files
committed
patch res.end for all transactions
1 parent c7de9c3 commit f9df1b4

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

packages/nextjs/src/common/wrapApiHandlerWithSentry.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
withIsolationScope,
88
} from '@sentry/core';
99
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core';
10-
import { isString, logger, objectify } from '@sentry/utils';
10+
import { isString, logger, objectify, vercelWaitUntil } from '@sentry/utils';
1111
import type { NextApiRequest } from 'next';
1212
import type { AugmentedNextApiResponse, NextApiHandler } from './types';
1313
import { flushSafelyWithTimeout } from './utils/responseEnd';
@@ -77,6 +77,15 @@ 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+
});
8089
try {
8190
return await wrappingTarget.apply(thisArg, args);
8291
} catch (e) {

0 commit comments

Comments
 (0)