Skip to content

Commit 456690f

Browse files
authored
feat(nestjs): Remove SentryService (#14759)
Closes: #13590
1 parent 381cd6c commit 456690f

File tree

2 files changed

+7
-71
lines changed

2 files changed

+7
-71
lines changed

docs/migration/v8-to-v9.md

+6
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ It will be removed in a future major version.
106106

107107
- The `getNumberOfUrlSegments` method has been removed. There are no replacements.
108108

109+
### `@sentry/nestjs`
110+
111+
- Removed `SentryService`.
112+
If you are using `@sentry/nestjs` you can safely remove any references to the `SentryService`.
113+
If you are using another package migrate to `@sentry/nestjs` and remove the `SentryService` afterwards.
114+
109115
## 5. Build Changes
110116

111117
Previously the CJS versions of the SDK code (wrongfully) contained compatibility statements for default exports in ESM:

packages/nestjs/src/setup.ts

+1-71
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,10 @@ import type {
55
ExecutionContext,
66
HttpServer,
77
NestInterceptor,
8-
OnModuleInit,
98
} from '@nestjs/common';
109
import { Catch, Global, HttpException, Injectable, Logger, Module } from '@nestjs/common';
1110
import { 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';
2312
import type { Observable } from 'rxjs';
2413
import { isExpectedError } from './helpers';
2514

@@ -177,40 +166,6 @@ export { SentryGlobalGraphQLFilter };
177166
*/
178167
export const SentryGlobalGenericFilter = SentryGlobalFilter;
179168

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-
214169
/**
215170
* Set up a root module that can be injected in nest applications.
216171
*/
@@ -222,48 +177,23 @@ class SentryModule {
222177
return {
223178
module: SentryModule,
224179
providers: [
225-
// eslint-disable-next-line deprecation/deprecation
226-
SentryService,
227180
{
228181
provide: APP_INTERCEPTOR,
229182
// eslint-disable-next-line deprecation/deprecation
230183
useClass: SentryTracingInterceptor,
231184
},
232185
],
233-
// eslint-disable-next-line deprecation/deprecation
234-
exports: [SentryService],
235186
};
236187
}
237188
}
238189
Global()(SentryModule);
239190
Module({
240191
providers: [
241-
// eslint-disable-next-line deprecation/deprecation
242-
SentryService,
243192
{
244193
provide: APP_INTERCEPTOR,
245194
// eslint-disable-next-line deprecation/deprecation
246195
useClass: SentryTracingInterceptor,
247196
},
248197
],
249-
// eslint-disable-next-line deprecation/deprecation
250-
exports: [SentryService],
251198
})(SentryModule);
252199
export { 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

Comments
 (0)