(target, [ctx, env])
| 52 | >(optionsCallback: (env: E) => CloudflareOptions, DurableObjectClass: C): C { |
| 53 | return new Proxy(DurableObjectClass, { |
| 54 | construct(target, [ctx, env]) { |
| 55 | setAsyncLocalStorageAsyncContextStrategy(); |
| 56 | const context = instrumentContext(ctx); |
| 57 | const options = getFinalOptions(optionsCallback(env), env); |
| 58 | const instrumentedEnv = instrumentEnv(env, options); |
| 59 | |
| 60 | const obj = new target(context, instrumentedEnv); |
| 61 | |
| 62 | // These are the methods that are available on a Durable Object |
| 63 | // ref: https://developers.cloudflare.com/durable-objects/api/base/ |
| 64 | // obj.alarm |
| 65 | // obj.fetch |
| 66 | // obj.webSocketError |
| 67 | // obj.webSocketClose |
| 68 | // obj.webSocketMessage |
| 69 | |
| 70 | // Any other public methods on the Durable Object instance are RPC calls. |
| 71 | |
| 72 | if (obj.fetch && typeof obj.fetch === 'function') { |
| 73 | obj.fetch = ensureInstrumented( |
| 74 | obj.fetch, |
| 75 | original => |
| 76 | new Proxy(original, { |
| 77 | apply(target, thisArg, args) { |
| 78 | return wrapRequestHandler({ options, request: args[0], context }, () => { |
| 79 | return Reflect.apply(target, thisArg, args); |
| 80 | }); |
| 81 | }, |
| 82 | }), |
| 83 | ); |
| 84 | } |
| 85 | |
| 86 | if (obj.alarm && typeof obj.alarm === 'function') { |
| 87 | // Alarms are independent invocations, so we start a new trace and link to the previous alarm |
| 88 | obj.alarm = wrapMethodWithSentry( |
| 89 | { options, context, spanName: 'alarm', spanOp: 'function', startNewTrace: true }, |
| 90 | obj.alarm, |
| 91 | ); |
| 92 | } |
| 93 | |
| 94 | if (obj.webSocketMessage && typeof obj.webSocketMessage === 'function') { |
| 95 | obj.webSocketMessage = wrapMethodWithSentry( |
| 96 | { options, context, spanName: 'webSocketMessage' }, |
| 97 | obj.webSocketMessage, |
| 98 | ); |
| 99 | } |
| 100 | |
| 101 | if (obj.webSocketClose && typeof obj.webSocketClose === 'function') { |
| 102 | obj.webSocketClose = wrapMethodWithSentry({ options, context, spanName: 'webSocketClose' }, obj.webSocketClose); |
| 103 | } |
| 104 | |
| 105 | if (obj.webSocketError && typeof obj.webSocketError === 'function') { |
| 106 | obj.webSocketError = wrapMethodWithSentry( |
| 107 | { options, context, spanName: 'webSocketError' }, |
| 108 | obj.webSocketError, |
| 109 | (_, error) => |
| 110 | captureException(error, { |
| 111 | mechanism: { |
nothing calls this directly
no test coverage detected