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 wrapQueueHandler(batch, 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.queue", name: `process ${batch.queue}`, attributes: { "faas.trigger": "pubsub", "messaging.destination.name": batch.queue, "messaging.system": "cloudflare", "messaging.operation.type": "process", "messaging.operation.name": "process", "messaging.batch.message_count": batch.messages.length, "messaging.message.retry.count": batch.messages.reduce((acc, message) => acc + message.attempts - 1, 0), [core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: "queue.process", [core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.faas.cloudflare.queue", [core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "task" } }, async () => { try { return await fn(); } catch (e) { core.captureException(e, { mechanism: { handled: false, type: "auto.faas.cloudflare.queue" } }); throw e; } finally { waitUntil(flush.flushAndDispose(client)); } } ); }); } function instrumentExportedHandlerQueue(handler, optionsCallback) { if (!("queue" in handler) || typeof handler.queue !== "function") { return; } handler.queue = instrument.ensureInstrumented( handler.queue, (original) => new Proxy(original, { apply(target, thisArg, args) { const [batch, 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 wrapQueueHandler(batch, options$1, context, () => target.apply(thisArg, args)); } }) ); } function instrumentWorkerEntrypointQueue(instance, options, context) { if (!instance.queue) { return; } const original = instance.queue.bind(instance); instance.queue = new Proxy(original, { apply(target, thisArg, args) { const [batch] = args; return wrapQueueHandler(batch, options, context, () => Reflect.apply(target, thisArg, args)); } }); } exports.instrumentExportedHandlerQueue = instrumentExportedHandlerQueue; exports.instrumentWorkerEntrypointQueue = instrumentWorkerEntrypointQueue; //# sourceMappingURL=instrumentQueue.js.map