From 5f76375a5f7b9c867f3c16f65d8a66fbec3a08b2 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Mon, 2 Sep 2024 11:11:26 +0000 Subject: [PATCH 1/2] feat(nextjs): Stabilize `captureRequestError` --- .../nextjs-15/instrumentation.ts | 2 +- .../nextjs/src/common/captureRequestError.ts | 20 +++++++++---------- packages/nextjs/src/common/index.ts | 3 ++- packages/nextjs/src/index.types.ts | 3 ++- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/dev-packages/e2e-tests/test-applications/nextjs-15/instrumentation.ts b/dev-packages/e2e-tests/test-applications/nextjs-15/instrumentation.ts index ca4a213e58ba..964f937c439a 100644 --- a/dev-packages/e2e-tests/test-applications/nextjs-15/instrumentation.ts +++ b/dev-packages/e2e-tests/test-applications/nextjs-15/instrumentation.ts @@ -10,4 +10,4 @@ export async function register() { } } -export const onRequestError = Sentry.experimental_captureRequestError; +export const onRequestError = Sentry.captureRequestError; diff --git a/packages/nextjs/src/common/captureRequestError.ts b/packages/nextjs/src/common/captureRequestError.ts index 8350a0f2e593..1556076619a0 100644 --- a/packages/nextjs/src/common/captureRequestError.ts +++ b/packages/nextjs/src/common/captureRequestError.ts @@ -13,17 +13,9 @@ type ErrorContext = { }; /** - * Reports errors for the Next.js `onRequestError` instrumentation hook. - * - * Notice: This function is experimental and not intended for production use. Breaking changes may be done to this funtion in any release. - * - * @experimental + * Reports errors passed to the the Next.js `onRequestError` instrumentation hook. */ -export function experimental_captureRequestError( - error: unknown, - request: RequestInfo, - errorContext: ErrorContext, -): void { +export function captureRequestError(error: unknown, request: RequestInfo, errorContext: ErrorContext): void { withScope(scope => { scope.setSDKProcessingMetadata({ request: { @@ -48,3 +40,11 @@ export function experimental_captureRequestError( }); }); } + +/** + * Reports errors passed to the the Next.js `onRequestError` instrumentation hook. + * + * @deprecated Use `captureRequestError` instead. + */ +// TODO(v9): Remove this export +export const experimental_captureRequestError = captureRequestError; diff --git a/packages/nextjs/src/common/index.ts b/packages/nextjs/src/common/index.ts index 23ddfa383772..354113637a30 100644 --- a/packages/nextjs/src/common/index.ts +++ b/packages/nextjs/src/common/index.ts @@ -11,4 +11,5 @@ export { wrapMiddlewareWithSentry } from './wrapMiddlewareWithSentry'; export { wrapPageComponentWithSentry } from './wrapPageComponentWithSentry'; export { wrapGenerationFunctionWithSentry } from './wrapGenerationFunctionWithSentry'; export { withServerActionInstrumentation } from './withServerActionInstrumentation'; -export { experimental_captureRequestError } from './captureRequestError'; +// eslint-disable-next-line deprecation/deprecation +export { experimental_captureRequestError, captureRequestError } from './captureRequestError'; diff --git a/packages/nextjs/src/index.types.ts b/packages/nextjs/src/index.types.ts index b093968bdebe..a272990162b3 100644 --- a/packages/nextjs/src/index.types.ts +++ b/packages/nextjs/src/index.types.ts @@ -141,4 +141,5 @@ export declare function wrapApiHandlerWithSentryVercelCrons(WrappingTarget: C): C; -export { experimental_captureRequestError } from './common/captureRequestError'; +// eslint-disable-next-line deprecation/deprecation +export { experimental_captureRequestError, captureRequestError } from './common/captureRequestError'; From 1b4f02c7034396f2a33aee09f5e42d4190fb2a85 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Mon, 2 Sep 2024 11:23:02 +0000 Subject: [PATCH 2/2] Add to e2e tests that technically don't support it --- .../e2e-tests/test-applications/nextjs-13/instrumentation.ts | 2 ++ .../e2e-tests/test-applications/nextjs-14/instrumentation.ts | 2 ++ .../test-applications/nextjs-app-dir/instrumentation.ts | 2 ++ 3 files changed, 6 insertions(+) diff --git a/dev-packages/e2e-tests/test-applications/nextjs-13/instrumentation.ts b/dev-packages/e2e-tests/test-applications/nextjs-13/instrumentation.ts index 1f889238427c..180685d41b4a 100644 --- a/dev-packages/e2e-tests/test-applications/nextjs-13/instrumentation.ts +++ b/dev-packages/e2e-tests/test-applications/nextjs-13/instrumentation.ts @@ -15,3 +15,5 @@ export function register() { }); } } + +export const onRequestError = Sentry.captureRequestError; diff --git a/dev-packages/e2e-tests/test-applications/nextjs-14/instrumentation.ts b/dev-packages/e2e-tests/test-applications/nextjs-14/instrumentation.ts index 0999fdd8e089..2dd920dfcc73 100644 --- a/dev-packages/e2e-tests/test-applications/nextjs-14/instrumentation.ts +++ b/dev-packages/e2e-tests/test-applications/nextjs-14/instrumentation.ts @@ -19,3 +19,5 @@ export function register() { }); } } + +export const onRequestError = Sentry.captureRequestError; diff --git a/dev-packages/e2e-tests/test-applications/nextjs-app-dir/instrumentation.ts b/dev-packages/e2e-tests/test-applications/nextjs-app-dir/instrumentation.ts index cd269ab160e7..a95bb9ee95ee 100644 --- a/dev-packages/e2e-tests/test-applications/nextjs-app-dir/instrumentation.ts +++ b/dev-packages/e2e-tests/test-applications/nextjs-app-dir/instrumentation.ts @@ -15,3 +15,5 @@ export function register() { }); } } + +export const onRequestError = Sentry.captureRequestError;