From 2896d9006693e803c7138c0501938c531140629b Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 18 Mar 2024 17:11:59 -0400 Subject: [PATCH 1/4] feat(v8/nextjs): Remove usage of class integrations --- packages/nextjs/src/server/httpIntegration.ts | 23 +++++++++---------- packages/nextjs/src/server/index.ts | 10 ++++---- .../server/onUncaughtExceptionIntegration.ts | 23 +++++++++---------- 3 files changed, 26 insertions(+), 30 deletions(-) diff --git a/packages/nextjs/src/server/httpIntegration.ts b/packages/nextjs/src/server/httpIntegration.ts index a170e86bd4ea..7663770144ed 100644 --- a/packages/nextjs/src/server/httpIntegration.ts +++ b/packages/nextjs/src/server/httpIntegration.ts @@ -1,13 +1,12 @@ -import { Integrations } from '@sentry/node-experimental'; +import { defineIntegration } from '@sentry/core'; +import { httpIntegration as originalHttpIntegration } from '@sentry/node-experimental'; +import type { IntegrationFn } from '@sentry/types'; -/** - * A custom HTTP integration where we always enable tracing. - */ -export class Http extends Integrations.Http { - public constructor(options?: ConstructorParameters[0]) { - super({ - ...options, - tracing: true, - }); - } -} +export const customHttpIntegration = ((options?: Parameters[0]) => { + return originalHttpIntegration({ + ...options, + tracing: true, + }); +}) satisfies IntegrationFn; + +export const httpIntegration = defineIntegration(customHttpIntegration); diff --git a/packages/nextjs/src/server/index.ts b/packages/nextjs/src/server/index.ts index 6ec2f500a8c3..a52a88a5db94 100644 --- a/packages/nextjs/src/server/index.ts +++ b/packages/nextjs/src/server/index.ts @@ -13,16 +13,14 @@ import { devErrorSymbolicationEventProcessor } from '../common/devErrorSymbolica import { getVercelEnv } from '../common/getVercelEnv'; import { isBuild } from '../common/utils/isBuild'; import { distDirRewriteFramesIntegration } from './distDirRewriteFramesIntegration'; -import { Http } from './httpIntegration'; -import { OnUncaughtException } from './onUncaughtExceptionIntegration'; +import { httpIntegration } from './httpIntegration'; +import { onUncaughtExceptionIntegration } from './onUncaughtExceptionIntegration'; export * from '@sentry/node-experimental'; export { captureUnderscoreErrorException } from '../common/_error'; export const Integrations = { ...OriginalIntegrations, - Http, - OnUncaughtException, }; const globalWithInjectedValues = global as typeof global & { @@ -85,8 +83,8 @@ export function init(options: NodeOptions): void { ...getDefaultIntegrations(options).filter( integration => !['Http', 'OnUncaughtException'].includes(integration.name), ), - new Http(), - new OnUncaughtException(), + httpIntegration(), + onUncaughtExceptionIntegration(), ]; // This value is injected at build time, based on the output directory specified in the build config. Though a default diff --git a/packages/nextjs/src/server/onUncaughtExceptionIntegration.ts b/packages/nextjs/src/server/onUncaughtExceptionIntegration.ts index e88520cf9534..4a4af5fb3868 100644 --- a/packages/nextjs/src/server/onUncaughtExceptionIntegration.ts +++ b/packages/nextjs/src/server/onUncaughtExceptionIntegration.ts @@ -1,13 +1,12 @@ -import { Integrations } from '@sentry/node-experimental'; +import { defineIntegration } from '@sentry/core'; +import { onUncaughtExceptionIntegration as originalOnUncaughtExceptionIntegration } from '@sentry/node-experimental'; +import type { IntegrationFn } from '@sentry/types'; -/** - * A custom OnUncaughtException integration that does not exit by default. - */ -export class OnUncaughtException extends Integrations.OnUncaughtException { - public constructor(options?: ConstructorParameters[0]) { - super({ - exitEvenIfOtherHandlersAreRegistered: false, - ...options, - }); - } -} +export const customOnUncaughtException = ((options?: Parameters[0]) => { + return originalOnUncaughtExceptionIntegration({ + exitEvenIfOtherHandlersAreRegistered: false, + ...options, + }); +}) satisfies IntegrationFn; + +export const onUncaughtExceptionIntegration = defineIntegration(customOnUncaughtException); From b22ad78d2d77fca45694a69a5cc971e7ae00de7f Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Tue, 19 Mar 2024 10:21:14 -0400 Subject: [PATCH 2/4] use typeof fix --- packages/nextjs/src/server/httpIntegration.ts | 13 +++---------- .../src/server/onUncaughtExceptionIntegration.ts | 15 ++++----------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/packages/nextjs/src/server/httpIntegration.ts b/packages/nextjs/src/server/httpIntegration.ts index 7663770144ed..1da29b5e866b 100644 --- a/packages/nextjs/src/server/httpIntegration.ts +++ b/packages/nextjs/src/server/httpIntegration.ts @@ -1,12 +1,5 @@ -import { defineIntegration } from '@sentry/core'; import { httpIntegration as originalHttpIntegration } from '@sentry/node-experimental'; -import type { IntegrationFn } from '@sentry/types'; -export const customHttpIntegration = ((options?: Parameters[0]) => { - return originalHttpIntegration({ - ...options, - tracing: true, - }); -}) satisfies IntegrationFn; - -export const httpIntegration = defineIntegration(customHttpIntegration); +export const httpIntegration: typeof originalHttpIntegration = options => { + return originalHttpIntegration({ ...options, tracing: true }); +}; diff --git a/packages/nextjs/src/server/onUncaughtExceptionIntegration.ts b/packages/nextjs/src/server/onUncaughtExceptionIntegration.ts index 4a4af5fb3868..d9eada65fa95 100644 --- a/packages/nextjs/src/server/onUncaughtExceptionIntegration.ts +++ b/packages/nextjs/src/server/onUncaughtExceptionIntegration.ts @@ -1,12 +1,5 @@ -import { defineIntegration } from '@sentry/core'; -import { onUncaughtExceptionIntegration as originalOnUncaughtExceptionIntegration } from '@sentry/node-experimental'; -import type { IntegrationFn } from '@sentry/types'; +import { onUncaughtExceptionIntegration as originalOnUncaughtExceptionIntegration } from '@sentry/node'; -export const customOnUncaughtException = ((options?: Parameters[0]) => { - return originalOnUncaughtExceptionIntegration({ - exitEvenIfOtherHandlersAreRegistered: false, - ...options, - }); -}) satisfies IntegrationFn; - -export const onUncaughtExceptionIntegration = defineIntegration(customOnUncaughtException); +export const onUncaughtExceptionIntegration: typeof originalOnUncaughtExceptionIntegration = options => { + return originalOnUncaughtExceptionIntegration({ ...options, exitEvenIfOtherHandlersAreRegistered: false }); +}; From c0065b02e58c146d384192275d2e19309f6b9490 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Tue, 19 Mar 2024 11:52:26 -0400 Subject: [PATCH 3/4] woops --- packages/nextjs/src/server/onUncaughtExceptionIntegration.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nextjs/src/server/onUncaughtExceptionIntegration.ts b/packages/nextjs/src/server/onUncaughtExceptionIntegration.ts index d9eada65fa95..8bbe348cb082 100644 --- a/packages/nextjs/src/server/onUncaughtExceptionIntegration.ts +++ b/packages/nextjs/src/server/onUncaughtExceptionIntegration.ts @@ -1,4 +1,4 @@ -import { onUncaughtExceptionIntegration as originalOnUncaughtExceptionIntegration } from '@sentry/node'; +import { onUncaughtExceptionIntegration as originalOnUncaughtExceptionIntegration } from '@sentry/node-experimental'; export const onUncaughtExceptionIntegration: typeof originalOnUncaughtExceptionIntegration = options => { return originalOnUncaughtExceptionIntegration({ ...options, exitEvenIfOtherHandlersAreRegistered: false }); From d0f8a5ac5fa8d13e62551ef7641642ef6337f829 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Tue, 19 Mar 2024 13:58:47 -0400 Subject: [PATCH 4/4] just delete test because its going away soon --- packages/nextjs/test/serverSdk.test.ts | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/packages/nextjs/test/serverSdk.test.ts b/packages/nextjs/test/serverSdk.test.ts index a9ce73588e7a..24a03f39a95b 100644 --- a/packages/nextjs/test/serverSdk.test.ts +++ b/packages/nextjs/test/serverSdk.test.ts @@ -151,18 +151,6 @@ describe('Server init()', () => { expect(httpIntegration).toBeDefined(); expect(httpIntegration).toEqual(expect.objectContaining({ _tracing: {} })); }); - - it('forces `_tracing = true` even if set to false', () => { - init({ - integrations: [new Integrations.Http({ tracing: false })], - }); - - const nodeInitOptions = nodeInit.mock.calls[0][0] as ModifiedInitOptions; - const httpIntegration = findIntegrationByName(nodeInitOptions.integrations, 'Http'); - - expect(httpIntegration).toBeDefined(); - expect(httpIntegration).toEqual(expect.objectContaining({ _tracing: {} })); - }); }); }); });