Skip to content
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

feat(nestjs): Remove SentryTracingInterceptor, SentryGlobalGraphQLFilter, SentryGlobalGenericFilter #14761

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import './instrument';

// Import other modules
import { HttpAdapterHost, NestFactory } from '@nestjs/core';
import { SentryGlobalGenericFilter } from '@sentry/nestjs/setup';
import { SentryGlobalFilter } from '@sentry/nestjs/setup';
import { AppModule } from './app.module';

const PORT = 3030;
Expand All @@ -12,7 +12,7 @@ async function bootstrap() {
const app = await NestFactory.create(AppModule);

const { httpAdapter } = app.get(HttpAdapterHost);
app.useGlobalFilters(new SentryGlobalGenericFilter(httpAdapter as any));
app.useGlobalFilters(new SentryGlobalFilter(httpAdapter as any));

await app.listen(PORT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ApolloDriver } from '@nestjs/apollo';
import { Logger, Module } from '@nestjs/common';
import { APP_FILTER } from '@nestjs/core';
import { GraphQLModule } from '@nestjs/graphql';
import { SentryGlobalGraphQLFilter, SentryModule } from '@sentry/nestjs/setup';
import { SentryGlobalFilter, SentryModule } from '@sentry/nestjs/setup';
import { AppResolver } from './app.resolver';

@Module({
Expand All @@ -19,7 +19,7 @@ import { AppResolver } from './app.resolver';
AppResolver,
{
provide: APP_FILTER,
useClass: SentryGlobalGraphQLFilter,
useClass: SentryGlobalFilter,
},
{
provide: Logger,
Expand Down
9 changes: 9 additions & 0 deletions docs/migration/v8-to-v9.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ It will be removed in a future major version.
- Removed `SentryService`.
If you are using `@sentry/nestjs` you can safely remove any references to the `SentryService`.
If you are using another package migrate to `@sentry/nestjs` and remove the `SentryService` afterwards.
- Removed `SentryTracingInterceptor`.
If you are using `@sentry/nestjs` you can safely remove any references to the `SentryTracingInterceptor`.
If you are using another package migrate to `@sentry/nestjs` and remove the `SentryTracingInterceptor` afterwards.
- Removed `SentryGlobalGenericFilter`.
Use the `SentryGlobalFilter` instead.
The `SentryGlobalFilter` is a drop-in replacement.
- Removed `SentryGlobalGraphQLFilter`.
Use the `SentryGlobalFilter` instead.
The `SentryGlobalFilter` is a drop-in replacement.

## 5. Build Changes

Expand Down
2 changes: 1 addition & 1 deletion packages/nestjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"build:types:watch": "tsc -p tsconfig.types.json --watch",
"build:tarball": "npm pack",
"circularDepCheck": "madge --circular src/index.ts && madge --circular src/setup.ts",
"clean": "rimraf build coverage sentry-node-*.tgz",
"clean": "rimraf build coverage sentry-nestjs-*.tgz ./*.d.ts ./*.d.ts.map",
"fix": "eslint . --format stylish --fix",
"lint": "eslint . --format stylish",
"test": "vitest run",
Expand Down
53 changes: 0 additions & 53 deletions packages/nestjs/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ interface ExpressRequest {

/**
* Interceptor to add Sentry tracing capabilities to Nest.js applications.
*
* @deprecated `SentryTracingInterceptor` is deprecated.
* If you are using `@sentry/nestjs` you can safely remove any references to the `SentryTracingInterceptor`.
* If you are using another package migrate to `@sentry/nestjs` and remove the `SentryTracingInterceptor` afterwards.
*/
class SentryTracingInterceptor implements NestInterceptor {
// used to exclude this class from being auto-instrumented
Expand Down Expand Up @@ -73,10 +69,7 @@ class SentryTracingInterceptor implements NestInterceptor {
return next.handle();
}
}
// eslint-disable-next-line deprecation/deprecation
Injectable()(SentryTracingInterceptor);
// eslint-disable-next-line deprecation/deprecation
export { SentryTracingInterceptor };

/**
* Global filter to handle exceptions and report them to Sentry.
Expand Down Expand Up @@ -122,50 +115,6 @@ class SentryGlobalFilter extends BaseExceptionFilter {
Catch()(SentryGlobalFilter);
export { SentryGlobalFilter };

/**
* Global filter to handle exceptions in NestJS + GraphQL applications and report them to Sentry.
*
* @deprecated `SentryGlobalGraphQLFilter` is deprecated. Use the `SentryGlobalFilter` instead. The `SentryGlobalFilter` is a drop-in replacement.
*/
class SentryGlobalGraphQLFilter {
private static readonly _logger = new Logger('ExceptionsHandler');
public readonly __SENTRY_INTERNAL__: boolean;

public constructor() {
this.__SENTRY_INTERNAL__ = true;
}

/**
* Catches exceptions and reports them to Sentry unless they are HttpExceptions.
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public catch(exception: unknown, host: ArgumentsHost): void {
// neither report nor log HttpExceptions
if (exception instanceof HttpException) {
throw exception;
}
if (exception instanceof Error) {
// eslint-disable-next-line deprecation/deprecation
SentryGlobalGraphQLFilter._logger.error(exception.message, exception.stack);
}
captureException(exception);
throw exception;
}
}
// eslint-disable-next-line deprecation/deprecation
Catch()(SentryGlobalGraphQLFilter);
// eslint-disable-next-line deprecation/deprecation
export { SentryGlobalGraphQLFilter };

/**
* Global filter to handle exceptions and report them to Sentry.
*
* This filter is a generic filter that can handle both HTTP and GraphQL exceptions.
*
* @deprecated `SentryGlobalGenericFilter` is deprecated. Use the `SentryGlobalFilter` instead. The `SentryGlobalFilter` is a drop-in replacement.
*/
export const SentryGlobalGenericFilter = SentryGlobalFilter;

/**
* Set up a root module that can be injected in nest applications.
*/
Expand All @@ -179,7 +128,6 @@ class SentryModule {
providers: [
{
provide: APP_INTERCEPTOR,
// eslint-disable-next-line deprecation/deprecation
useClass: SentryTracingInterceptor,
},
],
Expand All @@ -191,7 +139,6 @@ Module({
providers: [
{
provide: APP_INTERCEPTOR,
// eslint-disable-next-line deprecation/deprecation
useClass: SentryTracingInterceptor,
},
],
Expand Down
Loading