@sentry/node
Version:
Sentry Node SDK using OpenTelemetry for performance instrumentation
61 lines (58 loc) • 2.16 kB
JavaScript
import { SENTRY_LINK_TYPE, MESSAGING_SYSTEM, SENTRY_ORIGIN, SENTRY_OP } from '@sentry/conventions/attributes';
import { QUEUE_PROCESS, QUEUE, QUEUE_PUBLISH } from '@sentry/conventions/op';
import { startNewTrace, startInactiveSpan, getCurrentScope } from '@sentry/core';
import { toSentryAttributes, SentryBullMQSpan } from './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 QUEUE_PROCESS;
}
if (PRODUCER_OPERATIONS.has(operation)) {
return QUEUE_PUBLISH;
}
return 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 = getOpFromSpanName(name);
const origin = getOriginFromSpanName(name);
const attributes = {
[SENTRY_OP]: op,
[SENTRY_ORIGIN]: origin,
[MESSAGING_SYSTEM]: "bullmq",
...options?.attributes && toSentryAttributes(options.attributes)
};
const span = op === QUEUE_PROCESS ? startNewTrace(() => startInactiveSpan({ name, attributes })) : startInactiveSpan({ name, attributes, onlyIfParent: op === QUEUE });
if (context?.producerSpanContext) {
const producerSpanCtx = {
traceId: context.producerSpanContext.traceId,
spanId: context.producerSpanContext.spanId,
traceFlags: context.producerSpanContext.sampled ? 1 : 0
};
span.addLink({
context: producerSpanCtx,
attributes: {
[SENTRY_LINK_TYPE]: "message_origin"
}
});
}
return new SentryBullMQSpan(span, getCurrentScope());
}
}
export { SentryBullMQTracer };
//# sourceMappingURL=tracer.js.map