UNPKG

bullmq-otel

Version:
66 lines 1.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BullMQOtel = exports.BullMQOTelSpan = void 0; const api_1 = require("@opentelemetry/api"); class BullMQOTelContextManager { constructor() { this.contextAPI = api_1.context; } getMetadata(ctx) { const metadata = {}; api_1.propagation.inject(ctx, metadata); return JSON.stringify(metadata); } fromMetadata(activeCtx, metadata) { const metadataObj = JSON.parse(metadata); const ctx = api_1.propagation.extract(activeCtx, metadataObj); return ctx; } with(ctx, fn) { return this.contextAPI.with(ctx, fn); } active() { return this.contextAPI.active(); } } class BullMQOtelTracer { constructor(tracer) { this.tracer = tracer; } startSpan(name, options, context) { const span = this.tracer.startSpan(name, options, context); return new BullMQOTelSpan(span); } } class BullMQOTelSpan { constructor(span) { this.span = span; } setSpanOnContext(ctx) { return api_1.trace.setSpan(ctx, this.span); } setAttribute(key, value) { this.span.setAttribute(key, value); } setAttributes(attributes) { this.span.setAttributes(attributes); } addEvent(name, attributes, time) { this.span.addEvent(name, attributes, time); } recordException(exception, time) { this.span.recordException(exception, time); } end() { this.span.end(); } } exports.BullMQOTelSpan = BullMQOTelSpan; class BullMQOtel { constructor(tracerName, version) { this.tracer = new BullMQOtelTracer(api_1.trace.getTracer(tracerName, version)); this.contextManager = new BullMQOTelContextManager(); } } exports.BullMQOtel = BullMQOtel; //# sourceMappingURL=bullMQOtel.js.map