OpenTelemetry
Feed queue metrics into your application-owned telemetry stack with @queuebert/otel.
Install#
npm install @queuebert/otel @opentelemetry/api@^1.9Queuebert records through an OpenTelemetry Meter. It does not start an SDK, choose an exporter, serve a Prometheus endpoint, or automatically instrument BullMQ workers. Configure your SDK before importing application code and record events from your processing lifecycle.
Framework-independent metrics#
import { metrics } from '@opentelemetry/api';
import { createResourceAttributes, MetricsRegistry } from '@queuebert/otel';
const registry = new MetricsRegistry(
{
durationBuckets: [10, 50, 100, 500, 1000, 5000],
perJobNameMetrics: true,
maxJobNames: 100,
},
metrics.getMeter('email-worker.queuebert', '1.0.0'),
createResourceAttributes({
serviceName: 'email-worker',
deploymentEnvironment: 'production',
}),
);
registry.recordJobCompleted('emails', 'welcome', 82);
registry.recordJobFailed('emails', 'digest', 410);
registry.updateQueueCounts('emails', {
waiting: 12,
active: 2,
completed: 240,
failed: 4,
delayed: 1,
});
const snapshot = registry.getSnapshot();
const queuebertStats = registry.transformToQueuebertStats('emails');
// During shutdown, unregister observable callbacks:
registry.destroy();Durations above are milliseconds. Replace the illustrative numbers with measured job outcomes and live BullMQ counts. If you omit the meter, the global API meter is used; without a configured SDK/exporter, recording does not deliver metrics to a backend.
NestJS integration#
Install the Nest peers in addition to the API package:
npm install @queuebert/nest @nestjs/bullmq@^11 @nestjs/common@^11 @nestjs/core@^11 bullmq@^5import { Module } from '@nestjs/common';
import { QueuebertOTelModule } from '@queuebert/otel/nest';
@Module({
imports: [
QueuebertOTelModule.forRoot({
instrumentationName: 'email-worker.queuebert',
instrumentationVersion: '1.0.0',
resource: {
serviceName: 'email-worker',
deploymentEnvironment: 'production',
},
}),
],
})
export class TelemetryModule {}Inject QueuebertOTelService to record completed/failed jobs, update queue counts, and obtain snapshots. QUEUEBERT_OTEL_METER and QUEUEBERT_OTEL_TRACER expose the configured instances. Async configuration is available through forRootAsync().
The Nest import path is @queuebert/otel/nest, not @queuebert/nest/otel.
Metrics and cardinality#
The METRIC_NAMES export defines the stable names:
| Metric | Signal |
|---|---|
queuebert.job.completed | Completed-job counter |
queuebert.job.failed | Failed-job counter |
queuebert.job.duration | Processing-duration histogram |
queuebert.job.waiting | Observable waiting-job gauge |
queuebert.job.active | Observable active-job gauge |
queuebert.job.delayed | Observable delayed-job gauge |
queuebert.queue.throughput | Queue throughput |
maxJobNames bounds job-name cardinality; overflow names are aggregated under __other__. Use stable operation names instead of customer IDs or job IDs. Queuebert snapshot failure and success rates are fractions between 0 and 1, not percentages.