Skip to content

Commit b102817

Browse files
Lms24lforst
andauthored
feat(nextjs): Mark errors caught from NextJS wrappers as unhandled (#8893)
Mark errors caught in * `captureUnderscoreException` * `wrapApiHandlerWithSentry` * `callDataFetcherTraced` * `withErrorInstrumentation` * `wrapServerComponentWithSentry` as unhandled. For more details, see #8890, #6073 Co-authored-by: Luca Forstner <[email protected]>
1 parent 3d8b444 commit b102817

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

packages/nextjs/src/common/_error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export async function captureUnderscoreErrorException(contextOrProps: ContextOrP
4545
scope.addEventProcessor(event => {
4646
addExceptionMechanism(event, {
4747
type: 'instrument',
48-
handled: true,
48+
handled: false,
4949
data: {
5050
function: '_error.getInitialProps',
5151
},

packages/nextjs/src/common/utils/wrapperUtils.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
startTransaction,
77
} from '@sentry/core';
88
import type { Span, Transaction } from '@sentry/types';
9-
import { isString, tracingContextFromHeaders } from '@sentry/utils';
9+
import { addExceptionMechanism, isString, tracingContextFromHeaders } from '@sentry/utils';
1010
import type { IncomingMessage, ServerResponse } from 'http';
1111

1212
import { platformSupportsStreaming } from './platformSupportsStreaming';
@@ -47,7 +47,17 @@ export function withErrorInstrumentation<F extends (...args: any[]) => any>(
4747
return await origFunction.apply(this, origFunctionArguments);
4848
} catch (e) {
4949
// TODO: Extract error logic from `withSentry` in here or create a new wrapper with said logic or something like that.
50-
captureException(e);
50+
captureException(e, scope => {
51+
scope.addEventProcessor(event => {
52+
addExceptionMechanism(event, {
53+
handled: false,
54+
});
55+
return event;
56+
});
57+
58+
return scope;
59+
});
60+
5161
throw e;
5262
}
5363
};
@@ -221,7 +231,17 @@ export async function callDataFetcherTraced<F extends (...args: any[]) => Promis
221231
span.finish();
222232

223233
// TODO Copy more robust error handling over from `withSentry`
224-
captureException(err);
234+
captureException(err, scope => {
235+
scope.addEventProcessor(event => {
236+
addExceptionMechanism(event, {
237+
handled: false,
238+
});
239+
return event;
240+
});
241+
242+
return scope;
243+
});
244+
225245
throw err;
226246
}
227247
}

packages/nextjs/src/common/wrapApiHandlerWithSentry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export function withSentry(apiHandler: NextApiHandler, parameterizedRoute?: stri
191191
currentScope.addEventProcessor(event => {
192192
addExceptionMechanism(event, {
193193
type: 'instrument',
194-
handled: true,
194+
handled: false,
195195
data: {
196196
wrapped_handler: wrappingTarget.name,
197197
function: 'withSentry',

packages/nextjs/src/common/wrapServerComponentWithSentry.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
runWithAsyncContext,
66
startTransaction,
77
} from '@sentry/core';
8-
import { tracingContextFromHeaders } from '@sentry/utils';
8+
import { addExceptionMechanism, tracingContextFromHeaders } from '@sentry/utils';
99

1010
import { isNotFoundNavigationError, isRedirectNavigationError } from '../common/nextNavigationErrorUtils';
1111
import type { ServerComponentContext } from '../common/types';
@@ -63,7 +63,17 @@ export function wrapServerComponentWithSentry<F extends (...args: any[]) => any>
6363
// We don't want to report redirects
6464
} else {
6565
transaction.setStatus('internal_error');
66-
captureException(e);
66+
67+
captureException(e, scope => {
68+
scope.addEventProcessor(event => {
69+
addExceptionMechanism(event, {
70+
handled: false,
71+
});
72+
return event;
73+
});
74+
75+
return scope;
76+
});
6777
}
6878

6979
transaction.finish();

0 commit comments

Comments
 (0)