Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const core = require('@sentry/core'); const flush = require('../../flush.js'); const instrument = require('../../instrument.js'); const options = require('../../options.js'); const scopeUtils = require('../../scope-utils.js'); const sdk = require('../../sdk.js'); const instrumentContext = require('../../utils/instrumentContext.js'); const instrumentEnv = require('./instrumentEnv.js'); function wrapScheduledHandler(controller, options, context, fn) { return core.withIsolationScope((isolationScope) => { const waitUntil = context.waitUntil.bind(context); const client = sdk.init({ ...options, ctx: context }); isolationScope.setClient(client); scopeUtils.addCloudResourceContext(isolationScope); return core.startSpan( { op: "faas.cron", name: `Scheduled Cron ${controller.cron}`, attributes: { "faas.cron": controller.cron, "faas.time": new Date(controller.scheduledTime).toISOString(), "faas.trigger": "timer", [core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.faas.cloudflare.scheduled", [core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "task" } }, async () => { try { return await fn(); } catch (e) { core.captureException(e, { mechanism: { handled: false, type: "auto.faas.cloudflare.scheduled" } }); throw e; } finally { waitUntil(flush.flushAndDispose(client)); } } ); }); } function instrumentExportedHandlerScheduled(handler, optionsCallback) { if (!("scheduled" in handler) || typeof handler.scheduled !== "function") { return; } handler.scheduled = instrument.ensureInstrumented( handler.scheduled, (original) => new Proxy(original, { apply(target, thisArg, args) { const [controller, env, ctx] = args; const context = instrumentContext.instrumentContext(ctx); const options$1 = options.getFinalOptions(optionsCallback(env), env); args[1] = instrumentEnv.instrumentEnv(env, options$1); args[2] = context; return wrapScheduledHandler(controller, options$1, context, () => target.apply(thisArg, args)); } }) ); } function instrumentWorkerEntrypointScheduled(instance, options, context) { if (!instance.scheduled) { return; } const original = instance.scheduled.bind(instance); instance.scheduled = new Proxy(original, { apply(target, thisArg, args) { const [controller] = args; return wrapScheduledHandler(controller, options, context, () => Reflect.apply(target, thisArg, args)); } }); } exports.instrumentExportedHandlerScheduled = instrumentExportedHandlerScheduled; exports.instrumentWorkerEntrypointScheduled = instrumentWorkerEntrypointScheduled; //# sourceMappingURL=instrumentScheduled.js.map