11import type { Context , Span , SpanOptions , Tracer , TracerProvider } from '@opentelemetry/api' ;
2- import { trace } from '@opentelemetry/api' ;
2+ import { ProxyTracerProvider , trace } from '@opentelemetry/api' ;
33import { startInactiveSpan , startSpanManual } from '@sentry/core' ;
44
55/**
@@ -8,7 +8,8 @@ import { startInactiveSpan, startSpanManual } from '@sentry/core';
88 */
99export function setupOpenTelemetryTracer ( ) : void {
1010 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 ) ) ;
1213}
1314
1415class SentryCloudflareTraceProvider implements TracerProvider {
@@ -43,22 +44,23 @@ class SentryCloudflareTracer implements Tracer {
4344 return new Proxy ( sentrySpan , {
4445 get : ( target , p ) => {
4546 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 ;
6149 }
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+ } ) ;
6264 } ,
6365 } ) ;
6466 }
0 commit comments