Skip to content

Commit 7cdd7f4

Browse files
committed
remove unnecessary checks, add guard for default isolation scope
1 parent 1313a13 commit 7cdd7f4

File tree

1 file changed

+19
-8
lines changed
  • packages/node/src/integrations/tracing

1 file changed

+19
-8
lines changed

packages/node/src/integrations/tracing/koa.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import { registerInstrumentations } from '@opentelemetry/instrumentation';
22
import { KoaInstrumentation } from '@opentelemetry/instrumentation-koa';
33
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
4-
import { captureException, defineIntegration, getCurrentScope, spanToJSON } from '@sentry/core';
4+
import {
5+
captureException,
6+
defineIntegration,
7+
getDefaultIsolationScope,
8+
getIsolationScope,
9+
spanToJSON,
10+
} from '@sentry/core';
511
import type { IntegrationFn } from '@sentry/types';
12+
import { logger } from '@sentry/utils';
13+
import { DEBUG_BUILD } from '../../debug-build';
614

715
const _koaIntegration = (() => {
816
return {
@@ -12,13 +20,16 @@ const _koaIntegration = (() => {
1220
instrumentations: [
1321
new KoaInstrumentation({
1422
requestHook(span, info) {
15-
if (span.isRecording() && info.layerType === 'router') {
16-
const attributes = spanToJSON(span).data;
17-
const route = attributes && attributes[SemanticAttributes.HTTP_ROUTE];
18-
const method = info.context.request.method.toUpperCase() || 'GET';
19-
if (route && method) {
20-
getCurrentScope().setTransactionName(`${method} ${route}`);
21-
}
23+
if (getIsolationScope() === getDefaultIsolationScope()) {
24+
DEBUG_BUILD &&
25+
logger.warn('Isolation scope is default isolation scope - skipping setting transactionName');
26+
return;
27+
}
28+
const attributes = spanToJSON(span).data;
29+
const route = attributes && attributes[SemanticAttributes.HTTP_ROUTE];
30+
const method = info.context.request.method.toUpperCase() || 'GET';
31+
if (route) {
32+
getIsolationScope().setTransactionName(`${method} ${route}`);
2233
}
2334
},
2435
}),

0 commit comments

Comments
 (0)