8000 feat(node): Adds isolation scope forking to tRPC middleware · getsentry/sentry-javascript@3b34dca · GitHub
[go: up one dir, main page]

Skip to content

Commit 3b34dca

Browse files
committed
feat(node): Adds isolation scope forking to tRPC middleware
Writing tRPC handlers today and using top-level methods like `Sentry.setTag` isn't very intuitive as the isolations scope is not forked per procedure in our middleware. This PR changes the middleware to fork the isolation scope, while this is not 100% correct, as it breaks the one isolation scope per process/request model, it should be more intuitive and work better for most users. Resolves: #16262
1 parent 6281d6b commit 3b34dca

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

packages/core/src/trpc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getClient, withScope } from './currentScopes';
1+
import { getClient, withIsolationScope } from './currentScopes';
22
import { captureException } from './exports';
33
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from './semanticAttributes';
44
import { startSpanManual } from './tracing';
@@ -76,7 +76,7 @@ export function trpcMiddleware(options: SentryTrpcMiddlewareOptions = {}) {
7676
}
7777
}
7878

79-
return withScope(scope => {
79+
return withIsolationScope(scope => {
8080
scope.setContext('trpc', trpcContext);
8181
return startSpanManual(
8282
{

packages/core/test/lib/trpc.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('trpcMiddleware', () => {
2626
setExtra: vi.fn(),
2727
};
2828

29-
const withScope = vi.fn(callback => {
29+
const withIsolationScope = vi.fn(callback => {
3030
return callback(mockScope);
3131
});
3232

@@ -38,7 +38,7 @@ describe('trpcMiddleware', () => {
3838
client.init();
3939
vi.spyOn(currentScopes, 'getClient').mockReturnValue(mockClient);
4040
vi.spyOn(tracing, 'startSpanManual').mockImplementation((name, callback) => callback(mockSpan, () => {}));
41-
vi.spyOn(currentScopes, 'withScope').mockImplementation(withScope);
41+
vi.spyOn(currentScopes, 'withIsolationScope').mockImplementation(withIsolationScope);
4242
vi.spyOn(exports, 'captureException').mockImplementation(() => 'mock-event-id');
4343
});
4444

0 commit comments

Comments
 (0)
0