Skip to content

feat(v8/nextjs): Remove usage of class integrations #11182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions packages/nextjs/src/server/httpIntegration.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import { Integrations } from '@sentry/node-experimental';
import { httpIntegration as originalHttpIntegration } from '@sentry/node-experimental';

/**
* A custom HTTP integration where we always enable tracing.
*/
export class Http extends Integrations.Http {
public constructor(options?: ConstructorParameters<typeof Integrations.Http>[0]) {
super({
...options,
tracing: true,
});
}
}
export const httpIntegration: typeof originalHttpIntegration = options => {
return originalHttpIntegration({ ...options, tracing: true });
};
10 changes: 4 additions & 6 deletions packages/nextjs/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 & {
Expand Down Expand Up @@ -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
Expand Down
16 changes: 4 additions & 12 deletions packages/nextjs/src/server/onUncaughtExceptionIntegration.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import { Integrations } from '@sentry/node-experimental';
import { onUncaughtExceptionIntegration as originalOnUncaughtExceptionIntegration } from '@sentry/node-experimental';

/**
* A custom OnUncaughtException integration that does not exit by default.
*/
export class OnUncaughtException extends Integrations.OnUncaughtException {
public constructor(options?: ConstructorParameters<typeof Integrations.OnUncaughtException>[0]) {
super({
exitEvenIfOtherHandlersAreRegistered: false,
...options,
});
}
}
export const onUncaughtExceptionIntegration: typeof originalOnUncaughtExceptionIntegration = options => {
return originalOnUncaughtExceptionIntegration({ ...options, exitEvenIfOtherHandlersAreRegistered: false });
};
12 changes: 0 additions & 12 deletions packages/nextjs/test/serverSdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {} }));
});
});
});
});