@@ -31,18 +31,36 @@ class SentryCloudflareTraceProvider implements TracerProvider {
31
31
class SentryCloudflareTracer implements Tracer {
32
32
public constructor ( private readonly _tracer : Tracer ) { }
33
33
public startSpan ( name : string , options ?: SpanOptions ) : Span {
34
- try {
35
- return startInactiveSpan ( {
36
- name,
37
- ...options ,
38
- attributes : {
39
- ...options ?. attributes ,
40
- 'sentry.cloudflare_tracer' : true ,
41
- } ,
42
- } ) ;
43
- } finally {
44
- this . _tracer . startSpan ( name , options ) ;
45
- }
34
+ const topSpan = this . _tracer . startSpan ( name , options ) ;
35
+ const sentrySpan = startInactiveSpan ( {
36
+ name,
37
+ ...options ,
38
+ attributes : {
39
+ ...options ?. attributes ,
40
+ 'sentry.cloudflare_tracer' : true ,
41
+ } ,
42
+ } ) ;
43
+ return new Proxy ( sentrySpan , {
44
+ get : ( target , p ) => {
45
+ 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
+ } ) ;
61
+ }
62
+ } ,
63
+ } ) ;
46
64
}
47
65
48
66
/**
0 commit comments