diff --git a/docs/migration/v8-to-v9.md b/docs/migration/v8-to-v9.md index 4bcdfb4127b2..3dae1a2cfd5f 100644 --- a/docs/migration/v8-to-v9.md +++ b/docs/migration/v8-to-v9.md @@ -94,6 +94,12 @@ It will be removed in a future major version. TODO +### `@sentry/nestjs` + +- 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. + ## 5. Build Changes Previously the CJS versions of the SDK code (wrongfully) contained compatibility statements for default exports in ESM: diff --git a/packages/nestjs/src/setup.ts b/packages/nestjs/src/setup.ts index e2fa65205b9a..a5d670402d68 100644 --- a/packages/nestjs/src/setup.ts +++ b/packages/nestjs/src/setup.ts @@ -5,21 +5,10 @@ import type { ExecutionContext, HttpServer, NestInterceptor, - OnModuleInit, } from '@nestjs/common'; import { Catch, Global, HttpException, Injectable, Logger, Module } from '@nestjs/common'; import { APP_INTERCEPTOR, BaseExceptionFilter } from '@nestjs/core'; -import type { Span } from '@sentry/core'; -import { - SEMANTIC_ATTRIBUTE_SENTRY_OP, - SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, - captureException, - getClient, - getDefaultIsolationScope, - getIsolationScope, - logger, - spanToJSON, -} from '@sentry/core'; +import { captureException, getDefaultIsolationScope, getIsolationScope, logger } from '@sentry/core'; import type { Observable } from 'rxjs'; import { isExpectedError } from './helpers'; @@ -177,40 +166,6 @@ export { SentryGlobalGraphQLFilter }; */ 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; - - public constructor() { - this.__SENTRY_INTERNAL__ = true; - } - - /** - * Initializes the Sentry service and registers span attributes. - */ - public onModuleInit(): void { - // 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 - const client = getClient(); - if (client) { - client.on('spanStart', span => { - addNestSpanAttributes(span); - }); - } - } -} -// eslint-disable-next-line deprecation/deprecation -Injectable()(SentryService); -// eslint-disable-next-line deprecation/deprecation -export { SentryService }; - /** * Set up a root module that can be injected in nest applications. */ @@ -222,48 +177,23 @@ 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 }; - -function addNestSpanAttributes(span: Span): void { - const attributes = spanToJSON(span).data; - - // this is one of: app_creation, request_context, handler - const type = attributes['nestjs.type']; - - // If this is already set, or we have no nest.js span, no need to process again... - if (attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] || !type) { - return; - } - - span.setAttributes({ - [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.otel.nestjs', - [SEMANTIC_ATTRIBUTE_SENTRY_OP]: `${type}.nestjs`, - }); -}