Skip to content

Commit 16ee4bc

Browse files
fix(nestjs): create websocket handler inside isolation scope
1 parent 1c24af3 commit 16ee4bc

1 file changed

Lines changed: 13 additions & 16 deletions

File tree

‎packages/nestjs/src/setup.ts‎

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {
99
import { Catch, Global, HttpException, Injectable, Logger, Module } from '@nestjs/common';
1010
import { APP_INTERCEPTOR, BaseExceptionFilter } from '@nestjs/core';
1111
import { captureException, debug, getDefaultIsolationScope, getIsolationScope, isObjectLike, withIsolationScope } from '@sentry/core';
12-
import type { Observable } from 'rxjs';
12+
import { Observable } from 'rxjs';
1313
import { isExpectedError, isWsOrRpcException } from './helpers';
1414

1515
// Partial extract of FastifyRequest interface
@@ -53,21 +53,18 @@ class SentryTracingInterceptor implements NestInterceptor {
5353
const client = wsHost.getClient<{ nsp?: { name?: string } }>();
5454
const pattern = wsHost.getPattern?.();
5555

56-
const source = next.handle();
57-
return source.lift({
58-
call(subscriber, source) {
59-
return withIsolationScope(isolationScope => {
60-
if (pattern) {
61-
const namespace = client?.nsp?.name;
62-
isolationScope.setTransactionName(
63-
namespace ? `WS ${namespace} ${pattern}` : `WS ${pattern}`,
64-
);
65-
}
66-
67-
return source.subscribe(subscriber);
68-
});
69-
},
70-
});
56+
if (!pattern) {
57+
return next.handle();
58+
}
59+
60+
return new Observable(subscriber =>
61+
withIsolationScope(isolationScope => {
62+
const namespace = client?.nsp?.name;
63+
isolationScope.setTransactionName(namespace ? `WS ${namespace} ${pattern}` : `WS ${pattern}`);
64+
65+
return next.handle().subscribe(subscriber);
66+
}),
67+
);
7168
}
7269

7370
if (getIsolationScope() === getDefaultIsolationScope()) {

0 commit comments

Comments
 (0)