diff --git a/packages/nextjs/src/common/_error.ts b/packages/nextjs/src/common/_error.ts index 624aabdb3b98..1ad27cc0b67f 100644 --- a/packages/nextjs/src/common/_error.ts +++ b/packages/nextjs/src/common/_error.ts @@ -45,7 +45,7 @@ export async function captureUnderscoreErrorException(contextOrProps: ContextOrP scope.addEventProcessor(event => { addExceptionMechanism(event, { type: 'instrument', - handled: true, + handled: false, data: { function: '_error.getInitialProps', }, diff --git a/packages/nextjs/src/common/utils/wrapperUtils.ts b/packages/nextjs/src/common/utils/wrapperUtils.ts index a3cf13736900..062822f8bb42 100644 --- a/packages/nextjs/src/common/utils/wrapperUtils.ts +++ b/packages/nextjs/src/common/utils/wrapperUtils.ts @@ -6,7 +6,7 @@ import { startTransaction, } from '@sentry/core'; import type { Span, Transaction } from '@sentry/types'; -import { isString, tracingContextFromHeaders } from '@sentry/utils'; +import { addExceptionMechanism, isString, tracingContextFromHeaders } from '@sentry/utils'; import type { IncomingMessage, ServerResponse } from 'http'; import { platformSupportsStreaming } from './platformSupportsStreaming'; @@ -47,7 +47,17 @@ export function withErrorInstrumentation any>( return await origFunction.apply(this, origFunctionArguments); } catch (e) { // TODO: Extract error logic from `withSentry` in here or create a new wrapper with said logic or something like that. - captureException(e); + captureException(e, scope => { + scope.addEventProcessor(event => { + addExceptionMechanism(event, { + handled: false, + }); + return event; + }); + + return scope; + }); + throw e; } }; @@ -217,7 +227,17 @@ export async function callDataFetcherTraced Promis span.finish(); // TODO Copy more robust error handling over from `withSentry` - captureException(err); + captureException(err, scope => { + scope.addEventProcessor(event => { + addExceptionMechanism(event, { + handled: false, + }); + return event; + }); + + return scope; + }); + throw err; } } diff --git a/packages/nextjs/src/common/wrapApiHandlerWithSentry.ts b/packages/nextjs/src/common/wrapApiHandlerWithSentry.ts index 85ec0cb4b1c2..a41fa4f0996a 100644 --- a/packages/nextjs/src/common/wrapApiHandlerWithSentry.ts +++ b/packages/nextjs/src/common/wrapApiHandlerWithSentry.ts @@ -190,7 +190,7 @@ export function withSentry(apiHandler: NextApiHandler, parameterizedRoute?: stri currentScope.addEventProcessor(event => { addExceptionMechanism(event, { type: 'instrument', - handled: true, + handled: false, data: { wrapped_handler: wrappingTarget.name, function: 'withSentry', diff --git a/packages/nextjs/src/common/wrapServerComponentWithSentry.ts b/packages/nextjs/src/common/wrapServerComponentWithSentry.ts index 81f030fa824c..019765c27ce9 100644 --- a/packages/nextjs/src/common/wrapServerComponentWithSentry.ts +++ b/packages/nextjs/src/common/wrapServerComponentWithSentry.ts @@ -5,7 +5,7 @@ import { runWithAsyncContext, startTransaction, } from '@sentry/core'; -import { tracingContextFromHeaders } from '@sentry/utils'; +import { addExceptionMechanism, tracingContextFromHeaders } from '@sentry/utils'; import { isNotFoundNavigationError, isRedirectNavigationError } from '../common/nextNavigationErrorUtils'; import type { ServerComponentContext } from '../common/types'; @@ -62,7 +62,17 @@ export function wrapServerComponentWithSentry any> // We don't want to report redirects } else { transaction.setStatus('internal_error'); - captureException(e); + + captureException(e, scope => { + scope.addEventProcessor(event => { + addExceptionMechanism(event, { + handled: false, + }); + return event; + }); + + return scope; + }); } transaction.finish();