@@ -31,12 +31,15 @@ function wrapMethodWithSentry<T extends OriginalMethod>(
31
31
wrapperOptions : MethodWrapperOptions ,
32
32
handler : T ,
33
33
callback ?: ( ...args : Parameters < T > ) => void ,
34
+ noMark ?: true ,
34
35
) : T {
35
36
if ( isInstrumented ( handler ) ) {
36
37
return handler ;
37
38
}
38
39
39
- markAsInstrumented ( handler ) ;
40
+ if ( ! noMark ) {
41
+ markAsInstrumented ( handler ) ;
42
+ }
40
43
41
44
return new Proxy ( handler , {
42
45
apply ( target , thisArg , args : Parameters < T > ) {
@@ -235,49 +238,31 @@ function instrumentPrototype<T extends NewableFunction>(
235
238
target : T ,
236
239
options : CloudflareOptions ,
237
240
context : MethodWrapperOptions [ 'context' ] ,
238
- ) : typeof target . prototype {
239
- const sentryMethods = new Map < string | symbol , OriginalMethod > ( ) ;
240
- let proto = target . prototype ;
241
- const instrumentedPrototype = new Proxy ( proto , {
241
+ ) : T {
242
+ return new Proxy ( target . prototype , {
242
243
get ( target , prop , receiver ) {
243
- if ( sentryMethods . has ( prop ) ) {
244
- return sentryMethods . get ( prop ) ;
244
+ const value = Reflect . get ( target , prop , receiver ) ;
245
+ if ( prop === 'constructor' || typeof value !== 'function' ) {
246
+ return value ;
245
247
}
246
- return Reflect . get ( target , prop , receiver ) ;
248
+ const wrapped = wrapMethodWithSentry (
249
+ { options, context, spanName : prop . toString ( ) , spanOp : 'rpc' } ,
250
+ value ,
251
+ undefined ,
252
+ true ,
253
+ ) ;
254
+ const instrumented = new Proxy ( wrapped , {
255
+ get ( target , p , receiver ) {
256
+ if ( '__SENTRY_INSTRUMENTED__' === p ) {
257
+ return true ;
258
+ }
259
+ return Reflect . get ( target , p , receiver ) ;
260
+ } ,
261
+ } ) ;
262
+ Object . defineProperty ( receiver , prop , {
263
+ value : instrumented ,
264
+ } ) ;
265
+ return instrumented ;
247
266
} ,
248
267
} ) ;
249
- while ( proto && proto !== Object . prototype ) {
250
- for ( const method of Object . getOwnPropertyNames ( proto ) ) {
251
- if ( method === 'constructor' || sentryMethods . has ( method ) ) {
252
- continue ;
253
- }
254
-
255
- const value = Reflect . get ( proto , method , proto ) ;
256
- if ( typeof value === 'function' ) {
257
- sentryMethods . set (
258
- method ,
259
- wrapMethodWithSentry (
260
- {
261
- options,
262
- context,
263
- spanName : method ,
264
- spanOp : 'rpc' ,
265
- } ,
266
- // <editor-fold desc="Disable __SENTRY_INSTRUMENTED__ for prototype methods">
267
- new Proxy ( value , {
268
- set ( target , p , newValue , receiver ) : boolean {
269
- if ( '__SENTRY_INSTRUMENTED__' === p ) {
270
- return true ;
271
- }
272
- return Reflect . set ( target , p , newValue , receiver ) ;
273
- } ,
274
- } ) ,
275
- // </editor-fold>
276
- ) ,
277
- ) ;
278
- }
279
- }
280
- proto = Object . getPrototypeOf ( proto ) ;
281
- }
282
- return instrumentedPrototype ;
283
268
}
0 commit comments