Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const core = require('@sentry/core'); const async = require('./async.js'); const instrument = require('./instrument.js'); const instrumentEnv = require('./instrumentations/worker/instrumentEnv.js'); const options = require('./options.js'); const request = require('./request.js'); const instrumentContext = require('./utils/instrumentContext.js'); const rpcMeta = require('./utils/rpcMeta.js'); const rpcOptions = require('./utils/rpcOptions.js'); const wrapMethodWithSentry = require('./wrapMethodWithSentry.js'); function instrumentDurableObjectWithSentry(optionsCallback, DurableObjectClass) { return new Proxy(DurableObjectClass, { construct(target, [ctx, env]) { async.setAsyncLocalStorageAsyncContextStrategy(); const context = instrumentContext.instrumentContext(ctx); const options$1 = options.getFinalOptions(optionsCallback(env), env); const instrumentedEnv = instrumentEnv.instrumentEnv(env, options$1); const obj = new target(context, instrumentedEnv); if (obj.fetch && typeof obj.fetch === "function") { obj.fetch = instrument.ensureInstrumented( obj.fetch, (original) => new Proxy(original, { apply(target2, thisArg, args) { return request.wrapRequestHandler({ options: options$1, request: args[0], context }, () => { return Reflect.apply(target2, thisArg, args); }); } }) ); } if (obj.alarm && typeof obj.alarm === "function") { obj.alarm = wrapMethodWithSentry.wrapMethodWithSentry( { options: options$1, context, spanName: "alarm", spanOp: "function", startNewTrace: true }, obj.alarm ); } if (obj.webSocketMessage && typeof obj.webSocketMessage === "function") { obj.webSocketMessage = wrapMethodWithSentry.wrapMethodWithSentry( { options: options$1, context, spanName: "webSocketMessage" }, obj.webSocketMessage ); } if (obj.webSocketClose && typeof obj.webSocketClose === "function") { obj.webSocketClose = wrapMethodWithSentry.wrapMethodWithSentry({ options: options$1, context, spanName: "webSocketClose" }, obj.webSocketClose); } if (obj.webSocketError && typeof obj.webSocketError === "function") { obj.webSocketError = wrapMethodWithSentry.wrapMethodWithSentry( { options: options$1, context, spanName: "webSocketError" }, obj.webSocketError, (_, error) => core.captureException(error, { mechanism: { type: "auto.faas.cloudflare.durable_object_websocket", handled: false } }) ); } const rpcPropagation = rpcOptions.getEffectiveRpcPropagation(options$1); if (!rpcPropagation) { return obj; } const instrumentPrototypeMethods = Array.isArray(options$1.instrumentPrototypeMethods) ? options$1.instrumentPrototypeMethods : void 0; const allowSet = instrumentPrototypeMethods ? new Set(instrumentPrototypeMethods) : null; const alwaysTrace = options$1.enableRpcTracePropagation === void 0; const methodCache = /* @__PURE__ */ new Map(); return new Proxy(obj, { get(proxyTarget, prop, receiver) { const value = Reflect.get(proxyTarget, prop, receiver); if (typeof prop !== "string" || typeof value !== "function" || prop === "constructor") { return value; } const cached = methodCache.get(prop); if (cached) { return cached; } const boundMethod = value.bind(proxyTarget); if (prop in Object.prototype || Object.prototype.hasOwnProperty.call(proxyTarget, prop) || allowSet && !allowSet.has(prop)) { methodCache.set(prop, boundMethod); return boundMethod; } const tracedMethod = wrapMethodWithSentry.wrapMethodWithSentry( { options: options$1, context, spanName: prop, spanOp: "rpc" }, boundMethod, void 0, true ); if (alwaysTrace) { methodCache.set(prop, tracedMethod); return tracedMethod; } const wrappedMethod = ((...args) => { const { rpcMeta: rpcMeta$1 } = rpcMeta.extractRpcMeta(args); return rpcMeta$1 ? tracedMethod(...args) : boundMethod(...args); }); methodCache.set(prop, wrappedMethod); return wrappedMethod; } }); } }); } exports.instrumentDurableObjectWithSentry = instrumentDurableObjectWithSentry; //# sourceMappingURL=durableobject.js.map