Skip to content

Commit

Permalink
feat(nestjs): Deprecate SentryTracingInterceptor, SentryService, …
Browse files Browse the repository at this point in the history
…`SentryGlobalGenericFilter`, `SentryGlobalGraphQLFilter` (#14371)
  • Loading branch information
lforst authored Nov 20, 2024
1 parent 0aadc9b commit e35dc22
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/migration/draft-v9-migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@
## `@sentry/nestjs`

- Deprecated `@WithSentry`. Use `@SentryExceptionCaptured` instead.
- Deprecated `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.
- Deprecated `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.
- Deprecated `SentryGlobalGenericFilter`.
Use the `SentryGlobalFilter` instead.
The `SentryGlobalFilter` is a drop-in replacement.
- Deprecated `SentryGlobalGraphQLFilter`.
Use the `SentryGlobalFilter` instead.
The `SentryGlobalFilter` is a drop-in replacement.

## `@sentry/types`

Expand Down
25 changes: 25 additions & 0 deletions packages/nestjs/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import { isExpectedError } from './helpers';

/**
* 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 @@ -59,7 +63,9 @@ class SentryTracingInterceptor implements NestInterceptor {
return next.handle();
}
}
// eslint-disable-next-line deprecation/deprecation
Injectable()(SentryTracingInterceptor);
// eslint-disable-next-line deprecation/deprecation
export { SentryTracingInterceptor };

/**
Expand Down Expand Up @@ -108,6 +114,8 @@ 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');
Expand All @@ -127,24 +135,33 @@ class SentryGlobalGraphQLFilter {
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;

/**
* Service to set up Sentry performance tracing for Nest.js applications.
*
* @deprecated `SentryService` is deprecated.
* 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.
*/
class SentryService implements OnModuleInit {
public readonly __SENTRY_INTERNAL__: boolean;
Expand All @@ -168,7 +185,9 @@ class SentryService implements OnModuleInit {
}
}
}
// eslint-disable-next-line deprecation/deprecation
Injectable()(SentryService);
// eslint-disable-next-line deprecation/deprecation
export { SentryService };

/**
Expand All @@ -182,25 +201,31 @@ class SentryModule {
return {
module: SentryModule,
providers: [
// eslint-disable-next-line deprecation/deprecation
SentryService,
{
provide: APP_INTERCEPTOR,
// eslint-disable-next-line deprecation/deprecation
useClass: SentryTracingInterceptor,
},
],
// eslint-disable-next-line deprecation/deprecation
exports: [SentryService],
};
}
}
Global()(SentryModule);
Module({
providers: [
// eslint-disable-next-line deprecation/deprecation
SentryService,
{
provide: APP_INTERCEPTOR,
// eslint-disable-next-line deprecation/deprecation
useClass: SentryTracingInterceptor,
},
],
// eslint-disable-next-line deprecation/deprecation
exports: [SentryService],
})(SentryModule);
export { SentryModule };
Expand Down

0 comments on commit e35dc22

Please sign in to comment.