UNPKG

@sentry/node

Version:

Sentry Node SDK using OpenTelemetry for performance instrumentation

63 lines (59 loc) • 2.23 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const attributes = require('@sentry/conventions/attributes'); const op = require('@sentry/conventions/op'); const core = require('@sentry/core'); const span = require('./span.js'); const PRODUCER_OPERATIONS = /* @__PURE__ */ new Set(["add", "addbulk", "addflow", "addbulkflows"]); const CONSUMER_OPERATIONS = /* @__PURE__ */ new Set(["process"]); function getOperation(name) { return name.split(" ")[0].toLowerCase(); } function getOpFromSpanName(name) { const operation = getOperation(name); if (CONSUMER_OPERATIONS.has(operation)) { return op.QUEUE_PROCESS; } if (PRODUCER_OPERATIONS.has(operation)) { return op.QUEUE_PUBLISH; } return op.QUEUE; } function getOriginFromSpanName(name) { const operation = getOperation(name); if (CONSUMER_OPERATIONS.has(operation)) { return "auto.queue.bullmq.consumer"; } if (PRODUCER_OPERATIONS.has(operation)) { return "auto.queue.bullmq.producer"; } return "auto.queue.bullmq"; } class SentryBullMQTracer { startSpan(name, options, context) { const op$1 = getOpFromSpanName(name); const origin = getOriginFromSpanName(name); const attributes$1 = { [attributes.SENTRY_OP]: op$1, [attributes.SENTRY_ORIGIN]: origin, [attributes.MESSAGING_SYSTEM]: "bullmq", ...options?.attributes && span.toSentryAttributes(options.attributes) }; const span$1 = op$1 === op.QUEUE_PROCESS ? core.startNewTrace(() => core.startInactiveSpan({ name, attributes: attributes$1 })) : core.startInactiveSpan({ name, attributes: attributes$1, onlyIfParent: op$1 === op.QUEUE }); if (context?.producerSpanContext) { const producerSpanCtx = { traceId: context.producerSpanContext.traceId, spanId: context.producerSpanContext.spanId, traceFlags: context.producerSpanContext.sampled ? 1 : 0 }; span$1.addLink({ context: producerSpanCtx, attributes: { [attributes.SENTRY_LINK_TYPE]: "message_origin" } }); } return new span.SentryBullMQSpan(span$1, core.getCurrentScope()); } } exports.SentryBullMQTracer = SentryBullMQTracer; //# sourceMappingURL=tracer.js.map