This module provides automatic tracing instrumentation for BullMQ.
Compatible with OpenTelemetry JS API and SDK 1.0+
.
npm install --save @appsignal/opentelemetry-instrumentation-bullmq
[2.x, 3.x, 4.x, 5.x]
It's likely that the instrumentation would support earlier versions of BullMQ, but I haven't tested it.
OpenTelemetry BullMQ Instrumentation allows the user to automatically collect trace data from BullMQ jobs and workers and export them to the backend of choice.
To load the instrumentation, specify it in the instrumentations list to registerInstrumentations
. There is currently no configuration option.
const { NodeTracerProvider } = require("@opentelemetry/sdk-trace-node");
const { registerInstrumentations } = require("@opentelemetry/instrumentation");
const {
BullMQInstrumentation,
} = require("@appsignal/opentelemetry-instrumentation-bullmq");
const provider = new NodeTracerProvider();
provider.register();
registerInstrumentations({
instrumentations: [
new BullMQInstrumentation({
// configuration options, see below
}),
],
});
Name | Type | Default value | Description |
---|---|---|---|
emitCreateSpansForBulk |
boolean |
true |
Whether to emit a create span for each individual job enqueued by Queue.addBulk or FlowProducer.addBulk . The span representing the overall bulk operation is emitted regardless. |
emitCreateSpansForFlow |
boolean |
true |
Whether to emit a create span for each individual job enqueued by FlowProducer.add or FlowProducer.addBulk . The span representing the overall flow operation is emitted regardless. |
requireParentSpanForPublish |
boolean |
false |
Whether to omit emitting a publish span (and the create child spans for it, for bulk and flow operations) when there is no parent span, meaning that the span created would be the root span of a new trace. |
useProducerSpanAsConsumerParent |
boolean |
false |
Whether to use the producer kind (create or publish) span as the parent for the consumer kind (process) span. When set to true, the consumer and producer spans will be part of the same trace. When set to false, the consumer span will be in a separate trace from the producer span, and it will contain a link to the producer span. |
The instrumentation aims to comply with the OpenTelemetry Semantic Convention for Messaging Spans. Whenever possible, attributes from the semantic convention are used in these spans.
Name | Span kind | messaging.bullmq.operation.name attribute [1] |
Description |
---|---|---|---|
{queueName} publish |
PRODUCER |
Queue.add |
A new job is added to the queue. |
{queueName} publish |
INTERNAL [2] |
Queue.addBulk |
New jobs are added to the queue in bulk. |
{queueName} publish |
INTERNAL [3] |
FlowProducer.add |
A new job flow is added to a queue. |
(bulk) publish |
INTERNAL [2] [3] |
FlowProducer.addBulk |
New job flows are added to queues in bulk. |
{queueName} create |
PRODUCER |
Job.add |
Each of the individual jobs added to a queue. Only emitted in bulk or flow operations. Child span of a publish span. [4] |
{queueName} process |
CONSUMER |
Worker.run |
Each job execution by a worker. Linked to the corresponding producer span. [5] |
- [1]: Represents the BullMQ function that was called in the application in order to trigger this span to be emitted.
- [2]: When the
emitCreateSpansForBulk
configuration option is set tofalse
, it is aPRODUCER
span. - [3]: When the
emitCreateSpansForFlow
configuration option is set tofalse
, it is aPRODUCER
span. - [4]: Will not be emitted for calls to
Queue.addBulk
andFlowProducer.addBulk
when theemitCreateSpansForBulk
configuration option isfalse
, or for calls toFlowProducer.add
andFlowProducer.addBulk
when theemitCreateSpansForFlow
configuration option is set tofalse
. - [5]: The producer span may not have been emitted if the
requireParentSpanForPublish
is set totrue
. In this case, no link is established.
- For more information on OpenTelemetry, visit: https://opentelemetry.io/
- For more about OpenTelemetry JavaScript: https://github.com/open-telemetry/opentelemetry-js
- For help or feedback on this project, open an issue or submit a PR
Apache 2.0 - See LICENSE for more information.
Contributions are welcome. Feel free to open an issue or submit a PR. I would like to have this package included in opentelemetry-js-contrib at some point. Until then, it lives here.
BullMQ has a hard dependency on Redis, which means that Redis is (for now) a test dependency for the instrumentations. To run the tests, you should have a redis server running on localhost at the default port. If you have docker installed, you can just do docker-compose up
and be ready to go.