UNPKG

bullmq-otel

Version:
61 lines 1.69 kB
import { trace, context, propagation, } from '@opentelemetry/api'; class BullMQOTelContextManager { constructor() { this.contextAPI = context; } getMetadata(ctx) { const metadata = {}; propagation.inject(ctx, metadata); return JSON.stringify(metadata); } fromMetadata(activeCtx, metadata) { const metadataObj = JSON.parse(metadata); const ctx = 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); } } export class BullMQOTelSpan { constructor(span) { this.span = span; } setSpanOnContext(ctx) { return 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(); } } export class BullMQOtel { constructor(tracerName, version) { this.tracer = new BullMQOtelTracer(trace.getTracer(tracerName, version)); this.contextManager = new BullMQOTelContextManager(); } } //# sourceMappingURL=bullMQOtel.js.map