@@ -5,21 +5,10 @@ import type {
55 ExecutionContext ,
66 HttpServer ,
77 NestInterceptor ,
8- OnModuleInit ,
98} from '@nestjs/common' ;
109import { Catch , Global , HttpException , Injectable , Logger , Module } from '@nestjs/common' ;
1110import { APP_INTERCEPTOR , BaseExceptionFilter } from '@nestjs/core' ;
12- import type { Span } from '@sentry/core' ;
13- import {
14- SEMANTIC_ATTRIBUTE_SENTRY_OP ,
15- SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ,
16- captureException ,
17- getClient ,
18- getDefaultIsolationScope ,
19- getIsolationScope ,
20- logger ,
21- spanToJSON ,
22- } from '@sentry/core' ;
11+ import { captureException , getDefaultIsolationScope , getIsolationScope , logger } from '@sentry/core' ;
2312import type { Observable } from 'rxjs' ;
2413import { isExpectedError } from './helpers' ;
2514
@@ -46,10 +35,6 @@ interface ExpressRequest {
4635
4736/**
4837 * Interceptor to add Sentry tracing capabilities to Nest.js applications.
49- *
50- * @deprecated `SentryTracingInterceptor` is deprecated.
51- * If you are using `@sentry/nestjs` you can safely remove any references to the `SentryTracingInterceptor`.
52- * If you are using another package migrate to `@sentry/nestjs` and remove the `SentryTracingInterceptor` afterwards.
5338 */
5439class SentryTracingInterceptor implements NestInterceptor {
5540 // used to exclude this class from being auto-instrumented
@@ -84,10 +69,7 @@ class SentryTracingInterceptor implements NestInterceptor {
8469 return next . handle ( ) ;
8570 }
8671}
87- // eslint-disable-next-line deprecation/deprecation
8872Injectable ( ) ( SentryTracingInterceptor ) ;
89- // eslint-disable-next-line deprecation/deprecation
90- export { SentryTracingInterceptor } ;
9173
9274/**
9375 * Global filter to handle exceptions and report them to Sentry.
@@ -133,84 +115,6 @@ class SentryGlobalFilter extends BaseExceptionFilter {
133115Catch ( ) ( SentryGlobalFilter ) ;
134116export { SentryGlobalFilter } ;
135117
136- /**
137- * Global filter to handle exceptions in NestJS + GraphQL applications and report them to Sentry.
138- *
139- * @deprecated `SentryGlobalGraphQLFilter` is deprecated. Use the `SentryGlobalFilter` instead. The `SentryGlobalFilter` is a drop-in replacement.
140- */
141- class SentryGlobalGraphQLFilter {
142- private static readonly _logger = new Logger ( 'ExceptionsHandler' ) ;
143- public readonly __SENTRY_INTERNAL__ : boolean ;
144-
145- public constructor ( ) {
146- this . __SENTRY_INTERNAL__ = true ;
147- }
148-
149- /**
150- * Catches exceptions and reports them to Sentry unless they are HttpExceptions.
151- */
152- // eslint-disable-next-line @typescript-eslint/no-unused-vars
153- public catch ( exception : unknown , host : ArgumentsHost ) : void {
154- // neither report nor log HttpExceptions
155- if ( exception instanceof HttpException ) {
156- throw exception ;
157- }
158- if ( exception instanceof Error ) {
159- // eslint-disable-next-line deprecation/deprecation
160- SentryGlobalGraphQLFilter . _logger . error ( exception . message , exception . stack ) ;
161- }
162- captureException ( exception ) ;
163- throw exception ;
164- }
165- }
166- // eslint-disable-next-line deprecation/deprecation
167- Catch ( ) ( SentryGlobalGraphQLFilter ) ;
168- // eslint-disable-next-line deprecation/deprecation
169- export { SentryGlobalGraphQLFilter } ;
170-
171- /**
172- * Global filter to handle exceptions and report them to Sentry.
173- *
174- * This filter is a generic filter that can handle both HTTP and GraphQL exceptions.
175- *
176- * @deprecated `SentryGlobalGenericFilter` is deprecated. Use the `SentryGlobalFilter` instead. The `SentryGlobalFilter` is a drop-in replacement.
177- */
178- export const SentryGlobalGenericFilter = SentryGlobalFilter ;
179-
180- /**
181- * Service to set up Sentry performance tracing for Nest.js applications.
182- *
183- * @deprecated `SentryService` is deprecated.
184- * If you are using `@sentry/nestjs` you can safely remove any references to the `SentryService`.
185- * If you are using another package migrate to `@sentry/nestjs` and remove the `SentryService` afterwards.
186- */
187- class SentryService implements OnModuleInit {
188- public readonly __SENTRY_INTERNAL__ : boolean ;
189-
190- public constructor ( ) {
191- this . __SENTRY_INTERNAL__ = true ;
192- }
193-
194- /**
195- * Initializes the Sentry service and registers span attributes.
196- */
197- public onModuleInit ( ) : void {
198- // Sadly, NestInstrumentation has no requestHook, so we need to add the attributes here
199- // We register this hook in this method, because if we register it in the integration `setup`,
200- // it would always run even for users that are not even using Nest.js
201- const client = getClient ( ) ;
202- if ( client ) {
203- client . on ( 'spanStart' , span => {
204- addNestSpanAttributes ( span ) ;
205- } ) ;
206- }
207- }
208- }
209- // eslint-disable-next-line deprecation/deprecation
210- Injectable ( ) ( SentryService ) ;
211- // eslint-disable-next-line deprecation/deprecation
212- export { SentryService } ;
213-
214118/**
215119 * Set up a root module that can be injected in nest applications.
216120 */
@@ -222,48 +126,21 @@ class SentryModule {
222126 return {
223127 module : SentryModule ,
224128 providers : [
225- // eslint-disable-next-line deprecation/deprecation
226- SentryService ,
227129 {
228130 provide : APP_INTERCEPTOR ,
229- // eslint-disable-next-line deprecation/deprecation
230131 useClass : SentryTracingInterceptor ,
231132 } ,
232133 ] ,
233- // eslint-disable-next-line deprecation/deprecation
234- exports : [ SentryService ] ,
235134 } ;
236135 }
237136}
238137Global ( ) ( SentryModule ) ;
239138Module ( {
240139 providers : [
241- // eslint-disable-next-line deprecation/deprecation
242- SentryService ,
243140 {
244141 provide : APP_INTERCEPTOR ,
245- // eslint-disable-next-line deprecation/deprecation
246142 useClass : SentryTracingInterceptor ,
247143 } ,
248144 ] ,
249- // eslint-disable-next-line deprecation/deprecation
250- exports : [ SentryService ] ,
251145} ) ( SentryModule ) ;
252146export { SentryModule } ;
253-
254- function addNestSpanAttributes ( span : Span ) : void {
255- const attributes = spanToJSON ( span ) . data ;
256-
257- // this is one of: app_creation, request_context, handler
258- const type = attributes [ 'nestjs.type' ] ;
259-
260- // If this is already set, or we have no nest.js span, no need to process again...
261- if ( attributes [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] || ! type ) {
262- return ;
263- }
264-
265- span . setAttributes ( {
266- [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.http.otel.nestjs' ,
267- [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : `${ type } .nestjs` ,
268- } ) ;
269- }
0 commit comments