11import  {  registerInstrumentations  }  from  '@opentelemetry/instrumentation' ; 
22import  {  KoaInstrumentation  }  from  '@opentelemetry/instrumentation-koa' ; 
33import  {  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' ; 
511import  type  {  IntegrationFn  }  from  '@sentry/types' ; 
12+ import  {  logger  }  from  '@sentry/utils' ; 
13+ import  {  DEBUG_BUILD  }  from  '../../debug-build' ; 
614
715const  _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