1
1
import { registerInstrumentations } from '@opentelemetry/instrumentation' ;
2
2
import { KoaInstrumentation } from '@opentelemetry/instrumentation-koa' ;
3
3
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' ;
5
11
import type { IntegrationFn } from '@sentry/types' ;
12
+ import { logger } from '@sentry/utils' ;
13
+ import { DEBUG_BUILD } from '../../debug-build' ;
6
14
7
15
const _koaIntegration = ( ( ) => {
8
16
return {
@@ -12,13 +20,16 @@ const _koaIntegration = (() => {
12
20
instrumentations : [
13
21
new KoaInstrumentation ( {
14
22
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 } ` ) ;
22
33
}
23
34
} ,
24
35
} ) ,
0 commit comments