Skip to content

feat(node): Deprecate nestIntegration and setupNestErrorHandler in favor of using @sentry/nestjs #14374

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 2 commits into from
Nov 20, 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
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class AppModule {}
async function run(): Promise<void> {
const app = await NestFactory.create(AppModule);
const { httpAdapter } = app.get(HttpAdapterHost);
// eslint-disable-next-line deprecation/deprecation
Sentry.setupNestErrorHandler(app, new BaseExceptionFilter(httpAdapter));
await app.listen(port);
sendPortToRunner(port);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class AppModule {}
async function run(): Promise<void> {
const app = await NestFactory.create(AppModule);
const { httpAdapter } = app.get(HttpAdapterHost);
// eslint-disable-next-line deprecation/deprecation
Sentry.setupNestErrorHandler(app, new BaseExceptionFilter(httpAdapter));
await app.listen(port);
sendPortToRunner(port);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class AppModule {}
async function run(): Promise<void> {
const app = await NestFactory.create(AppModule);
const { httpAdapter } = app.get(HttpAdapterHost);
// eslint-disable-next-line deprecation/deprecation
Sentry.setupNestErrorHandler(app, new BaseExceptionFilter(httpAdapter));
await app.listen(port);
sendPortToRunner(port);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ async function run(): Promise<void> {
await app.listen(port);

const { httpAdapter } = app.get(HttpAdapterHost);
// eslint-disable-next-line deprecation/deprecation
Sentry.setupNestErrorHandler(app, new BaseExceptionFilter(httpAdapter));
sendPortToRunner(port);
}
Expand Down
2 changes: 2 additions & 0 deletions docs/migration/draft-v9-migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@
## Server-side SDKs (`@sentry/node` and all dependents)

- Deprecated `processThreadBreadcrumbIntegration` in favor of `childProcessIntegration`. Functionally they are the same.
- Deprecated `nestIntegration`. Use the NestJS SDK (`@sentry/nestjs`) instead.
- Deprecated `setupNestErrorHandler`. Use the NestJS SDK (`@sentry/nestjs`) instead.
2 changes: 2 additions & 0 deletions packages/astro/src/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export {
mysql2Integration,
mysqlIntegration,
nativeNodeFetchIntegration,
// eslint-disable-next-line deprecation/deprecation
nestIntegration,
NodeClient,
nodeContextIntegration,
Expand Down Expand Up @@ -118,6 +119,7 @@ export {
setupExpressErrorHandler,
setupHapiErrorHandler,
setupKoaErrorHandler,
// eslint-disable-next-line deprecation/deprecation
setupNestErrorHandler,
setUser,
spanToBaggageHeader,
Expand Down
2 changes: 2 additions & 0 deletions packages/aws-serverless/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ export {
mysql2Integration,
redisIntegration,
tediousIntegration,
// eslint-disable-next-line deprecation/deprecation
nestIntegration,
// eslint-disable-next-line deprecation/deprecation
setupNestErrorHandler,
postgresIntegration,
prismaIntegration,
Expand Down
2 changes: 2 additions & 0 deletions packages/bun/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ export {
mysql2Integration,
redisIntegration,
tediousIntegration,
// eslint-disable-next-line deprecation/deprecation
nestIntegration,
// eslint-disable-next-line deprecation/deprecation
setupNestErrorHandler,
postgresIntegration,
prismaIntegration,
Expand Down
2 changes: 2 additions & 0 deletions packages/google-cloud-serverless/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ export {
mysql2Integration,
redisIntegration,
tediousIntegration,
// eslint-disable-next-line deprecation/deprecation
nestIntegration,
// eslint-disable-next-line deprecation/deprecation
setupNestErrorHandler,
postgresIntegration,
prismaIntegration,
Expand Down
10 changes: 10 additions & 0 deletions packages/nestjs/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { nestIntegration as nestIntegrationAlias } from '@sentry/node';

export * from '@sentry/node';

/**
* Integration capturing tracing data for NestJS.
*/
// eslint-disable-next-line deprecation/deprecation
export const nestIntegration = nestIntegrationAlias;

// TODO(v9): Export custom `getDefaultIntegrations` from this SDK that automatically registers the `nestIntegration`.

export { init } from './sdk';

export {
Expand Down
1 change: 1 addition & 0 deletions packages/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export { mongooseIntegration } from './integrations/tracing/mongoose';
export { mysqlIntegration } from './integrations/tracing/mysql';
export { mysql2Integration } from './integrations/tracing/mysql2';
export { redisIntegration } from './integrations/tracing/redis';
// eslint-disable-next-line deprecation/deprecation
export { nestIntegration, setupNestErrorHandler } from './integrations/tracing/nest/nest';
export { postgresIntegration } from './integrations/tracing/postgres';
export { prismaIntegration } from './integrations/tracing/prisma';
Expand Down
2 changes: 2 additions & 0 deletions packages/node/src/integrations/tracing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function getAutoPerformanceIntegrations(): Integration[] {
// See https://github.com/prisma/prisma/issues/23410
// TODO v8: Figure out a better solution for this, maybe only disable in ESM mode?
// prismaIntegration(),
// eslint-disable-next-line deprecation/deprecation
nestIntegration(),
hapiIntegration(),
koaIntegration(),
Expand All @@ -64,6 +65,7 @@ export function getOpenTelemetryInstrumentationToPreload(): (((options?: any) =>
instrumentKafka,
instrumentKoa,
instrumentLruMemoizer,
// eslint-disable-next-line deprecation/deprecation
instrumentNest,
instrumentMongo,
instrumentMongoose,
Expand Down
31 changes: 20 additions & 11 deletions packages/node/src/integrations/tracing/nest/nest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
getIsolationScope,
spanToJSON,
} from '@sentry/core';
import type { IntegrationFn, Span } from '@sentry/types';
import { logger } from '@sentry/utils';
import type { Span } from '@sentry/types';
import { consoleSandbox, logger } from '@sentry/utils';
import { generateInstrumentOnce } from '../../../otel/instrument';
import { SentryNestEventInstrumentation } from './sentry-nest-event-instrumentation';
import { SentryNestInstrumentation } from './sentry-nest-instrumentation';
Expand Down Expand Up @@ -39,26 +39,35 @@ export const instrumentNest = Object.assign(
{ id: INTEGRATION_NAME },
);

const _nestIntegration = (() => {
/**
* Integration capturing tracing data for NestJS.
*
* @deprecated The `nestIntegration` is deprecated. Instead, use the NestJS SDK directly (`@sentry/nestjs`), or use the `nestIntegration` export from `@sentry/nestjs`.
*/
export const nestIntegration = defineIntegration(() => {
return {
name: INTEGRATION_NAME,
setupOnce() {
instrumentNest();
},
};
}) satisfies IntegrationFn;

/**
* Nest framework integration
*
* Capture tracing data for nest.
*/
export const nestIntegration = defineIntegration(_nestIntegration);
});

/**
* Setup an error handler for Nest.
*
* @deprecated `setupNestErrorHandler` is deprecated.
* Instead use the `@sentry/nestjs` package, which has more functional APIs for capturing errors.
* See the [`@sentry/nestjs` Setup Guide](https://docs.sentry.io/platforms/javascript/guides/nestjs/) for how to set up the Sentry NestJS SDK.
*/
export function setupNestErrorHandler(app: MinimalNestJsApp, baseFilter: NestJsErrorFilter): void {
consoleSandbox(() => {
// eslint-disable-next-line no-console
console.warn(
'[Sentry] Warning: You used the `setupNestErrorHandler()` method to set up Sentry error monitoring. This function is deprecated and will be removed in the next major version. Instead, it is recommended to use the `@sentry/nestjs` package. To set up the NestJS SDK see: https://docs.sentry.io/platforms/javascript/guides/nestjs/',
);
});

// Sadly, NestInstrumentation has no requestHook, so we need to add the attributes here
// We register this hook in this method, because if we register it in the integration `setup`,
// it would always run even for users that are not even using Nest.js
Expand Down
2 changes: 2 additions & 0 deletions packages/remix/src/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export {
mysql2Integration,
mysqlIntegration,
nativeNodeFetchIntegration,
// eslint-disable-next-line deprecation/deprecation
nestIntegration,
NodeClient,
nodeContextIntegration,
Expand Down Expand Up @@ -115,6 +116,7 @@ export {
setupExpressErrorHandler,
setupHapiErrorHandler,
setupKoaErrorHandler,
// eslint-disable-next-line deprecation/deprecation
setupNestErrorHandler,
setUser,
spanToBaggageHeader,
Expand Down
2 changes: 2 additions & 0 deletions packages/solidstart/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export {
mysql2Integration,
mysqlIntegration,
nativeNodeFetchIntegration,
// eslint-disable-next-line deprecation/deprecation
nestIntegration,
NodeClient,
nodeContextIntegration,
Expand Down Expand Up @@ -106,6 +107,7 @@ export {
setupExpressErrorHandler,
setupHapiErrorHandler,
setupKoaErrorHandler,
// eslint-disable-next-line deprecation/deprecation
setupNestErrorHandler,
setUser,
spanToBaggageHeader,
Expand Down
2 changes: 2 additions & 0 deletions packages/sveltekit/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export {
mysql2Integration,
mysqlIntegration,
nativeNodeFetchIntegration,
// eslint-disable-next-line deprecation/deprecation
nestIntegration,
NodeClient,
nodeContextIntegration,
Expand Down Expand Up @@ -108,6 +109,7 @@ export {
setupExpressErrorHandler,
setupHapiErrorHandler,
setupKoaErrorHandler,
// eslint-disable-next-line deprecation/deprecation
setupNestErrorHandler,
setUser,
spanToBaggageHeader,
Expand Down
Loading