1
1
import type { Context , Span , SpanOptions , Tracer , TracerProvider } from '@opentelemetry/api' ;
2
- import { trace } from '@opentelemetry/api' ;
2
+ import { ProxyTracerProvider , trace } from '@opentelemetry/api' ;
3
3
import { startInactiveSpan , startSpanManual } from '@sentry/core' ;
4
4
5
5
/**
@@ -8,7 +8,8 @@ import { startInactiveSpan, startSpanManual } from '@sentry/core';
8
8
*/
9
9
export function setupOpenTelemetryTracer ( ) : void {
10
10
const current = trace . getTracerProvider ( ) ;
11
- trace . setGlobalTracerProvider ( new SentryCloudflareTraceProvider ( current ) ) ;
11
+ const delegate = current instanceof ProxyTracerProvider ? current . getDelegate ( ) : current ;
12
+ trace . setGlobalTracerProvider ( new SentryCloudflareTraceProvider ( delegate ) ) ;
12
13
}
13
14
14
15
class SentryCloudflareTraceProvider implements TracerProvider {
@@ -43,22 +44,23 @@ class SentryCloudflareTracer implements Tracer {
43
44
return new Proxy ( sentrySpan , {
44
45
get : ( target , p ) => {
45
46
const propertyValue = Reflect . get ( target , p ) ;
46
- if ( typeof propertyValue === 'function' ) {
47
- const proxyTo = Reflect . get ( topSpan , p ) ;
48
- if ( typeof proxyTo !== 'function' ) {
49
- return propertyValue ;
50
- }
51
- return new Proxy ( propertyValue , {
52
- apply : ( target , thisArg , argArray ) => {
53
- try {
54
- Reflect . apply ( proxyTo , topSpan , argArray ) ;
55
- } catch ( e ) {
56
- //
57
- }
58
- return Reflect . apply ( target , thisArg , argArray ) ;
59
- } ,
60
- } ) ;
47
+ if ( typeof propertyValue !== 'function' ) {
48
+ return propertyValue ;
61
49
}
50
+ const proxyTo = Reflect . get ( topSpan , p ) ;
51
+ if ( typeof proxyTo !== 'function' ) {
52
+ return propertyValue ;
53
+ }
54
+ return new Proxy ( propertyValue , {
55
+ apply : ( target , thisArg , argArray ) => {
56
+ try {
57
+ Reflect . apply ( proxyTo , topSpan , argArray ) ;
58
+ } catch ( e ) {
59
+ //
60
+ }
61
+ return Reflect . apply ( target , thisArg , argArray ) ;
62
+ } ,
63
+ } ) ;
62
64
} ,
63
65
} ) ;
64
66
}
0 commit comments