Skip to content

Commit dca400b

Browse files
AbhiPrasadcadesalaberry
authored andcommitted
feat(v8/nextjs): Remove usage of class integrations (getsentry#11182)
In order to proceed with removing `Sentry.Integrations.X` as per getsentry#8844, there's still some places to clean up. This does conflict with getsentry#11016, but not sure when that merges in, so opening this in the meantime to unblock the integrations cleanup work. if we think the OTEL nextjs work will merge in sooner then the next 1-2 days, I'm happy to leave this alone for now!
1 parent 70045d9 commit dca400b

File tree

4 files changed

+12
-42
lines changed

4 files changed

+12
-42
lines changed
Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
1-
import { Integrations } from '@sentry/node-experimental';
1+
import { httpIntegration as originalHttpIntegration } from '@sentry/node-experimental';
22

3-
/**
4-
* A custom HTTP integration where we always enable tracing.
5-
*/
6-
export class Http extends Integrations.Http {
7-
public constructor(options?: ConstructorParameters<typeof Integrations.Http>[0]) {
8-
super({
9-
...options,
10-
tracing: true,
11-
});
12-
}
13-
}
3+
export const httpIntegration: typeof originalHttpIntegration = options => {
4+
return originalHttpIntegration({ ...options, tracing: true });
5+
};

packages/nextjs/src/server/index.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@ import { devErrorSymbolicationEventProcessor } from '../common/devErrorSymbolica
1313
import { getVercelEnv } from '../common/getVercelEnv';
1414
import { isBuild } from '../common/utils/isBuild';
1515
import { distDirRewriteFramesIntegration } from './distDirRewriteFramesIntegration';
16-
import { Http } from './httpIntegration';
17-
import { OnUncaughtException } from './onUncaughtExceptionIntegration';
16+
import { httpIntegration } from './httpIntegration';
17+
import { onUncaughtExceptionIntegration } from './onUncaughtExceptionIntegration';
1818

1919
export * from '@sentry/node-experimental';
2020
export { captureUnderscoreErrorException } from '../common/_error';
2121

2222
export const Integrations = {
2323
...OriginalIntegrations,
24-
Http,
25-
OnUncaughtException,
2624
};
2725

2826
const globalWithInjectedValues = global as typeof global & {
@@ -85,8 +83,8 @@ export function init(options: NodeOptions): void {
8583
...getDefaultIntegrations(options).filter(
8684
integration => !['Http', 'OnUncaughtException'].includes(integration.name),
8785
),
88-
new Http(),
89-
new OnUncaughtException(),
86+
httpIntegration(),
87+
onUncaughtExceptionIntegration(),
9088
];
9189

9290
// This value is injected at build time, based on the output directory specified in the build config. Though a default
Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
1-
import { Integrations } from '@sentry/node-experimental';
1+
import { onUncaughtExceptionIntegration as originalOnUncaughtExceptionIntegration } from '@sentry/node-experimental';
22

3-
/**
4-
* A custom OnUncaughtException integration that does not exit by default.
5-
*/
6-
export class OnUncaughtException extends Integrations.OnUncaughtException {
7-
public constructor(options?: ConstructorParameters<typeof Integrations.OnUncaughtException>[0]) {
8-
super({
9-
exitEvenIfOtherHandlersAreRegistered: false,
10-
...options,
11-
});
12-
}
13-
}
3+
export const onUncaughtExceptionIntegration: typeof originalOnUncaughtExceptionIntegration = options => {
4+
return originalOnUncaughtExceptionIntegration({ ...options, exitEvenIfOtherHandlersAreRegistered: false });
5+
};

packages/nextjs/test/serverSdk.test.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,6 @@ describe('Server init()', () => {
151151
expect(httpIntegration).toBeDefined();
152152
expect(httpIntegration).toEqual(expect.objectContaining({ _tracing: {} }));
153153
});
154-
155-
it('forces `_tracing = true` even if set to false', () => {
156-
init({
157-
integrations: [new Integrations.Http({ tracing: false })],
158-
});
159-
160-
const nodeInitOptions = nodeInit.mock.calls[0][0] as ModifiedInitOptions;
161-
const httpIntegration = findIntegrationByName(nodeInitOptions.integrations, 'Http');
162-
163-
expect(httpIntegration).toBeDefined();
164-
expect(httpIntegration).toEqual(expect.objectContaining({ _tracing: {} }));
165-
});
166154
});
167155
});
168156
});

0 commit comments

Comments
 (0)