Skip to content

Traces

A failed job tells you that it failed. Its trace tells you why: the HTTP request that added it, each attempt, and every database query and API call the worker made, with timings. Bullship receives the spans your apps already send with OpenTelemetry and shows them in the job’s Trace tab. When an attempt fails, the Error tab names the call that failed, such as UPDATE invoices on worker failed after 30.0 s: canceling statement due to statement timeout, and links to it in the trace.

Bullship only keeps traces that include a BullMQ job’s span, so it doesn’t become a general tracing backend. Spans stay in traces.db in the data directory; nothing is written to your Redis.

Make a long random token and give it to Bullship:

BULLSHIP_TRACES_TOKEN=$(openssl rand -hex 24)

Bullship then accepts OTLP over HTTP, protobuf or JSON, optionally gzipped, at /otlp/v1/traces. Without the token, the endpoint doesn’t exist.

Your app needs three things: the OpenTelemetry SDK, BullMQ’s telemetry, and an exporter pointed at Bullship. Start the SDK before anything else loads, in its own file:

npm install @opentelemetry/sdk-node @opentelemetry/auto-instrumentations-node bullmq-otel
instrumentation.mjs
import { register } from 'node:module'
import { NodeSDK } from '@opentelemetry/sdk-node'
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node'
// Lets the SDK see `import` statements in an ES module app; a CommonJS app can leave it out.
register('@opentelemetry/instrumentation/hook.mjs', import.meta.url)
new NodeSDK({ instrumentations: [getNodeAutoInstrumentations()] }).start()

Give your queues and workers BullMQ’s telemetry, so BullMQ makes a span for each job it adds and each attempt it runs:

import { Queue, Worker } from 'bullmq'
import { BullMQOtel } from 'bullmq-otel'
const telemetry = new BullMQOtel({ tracerName: 'bullmq' })
const queue = new Queue('invoices', { connection, telemetry })
const worker = new Worker('invoices', processor, { connection, telemetry })

Then start the app with the SDK loaded first and the exporter pointed at Bullship:

OTEL_SERVICE_NAME=api \
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://bullship.example.com/otlp/v1/traces \
OTEL_EXPORTER_OTLP_TRACES_HEADERS="Authorization=Bearer <BULLSHIP_TRACES_TOKEN>" \
node --import ./instrumentation.mjs server.js

The auto-instrumentations record HTTP requests, fetch, database clients such as pg and mysql2, and Redis, so the Trace tab shows the calls without changes to your processors. Their Redis spans copy the job’s data into db.statement; Bullship redacts it like the job’s data.

If your apps already send traces through an OpenTelemetry Collector, add Bullship as one more otlphttp exporter next to the backend you use:

exporters:
otlphttp/bullship:
endpoint: https://bullship.example.com/otlp
headers: { Authorization: 'Bearer ${env:BULLSHIP_TRACES_TOKEN}' }

BullMQ saves the trace context in each job, so the worker’s spans join the request that added the job, even in another service. A job whose producer isn’t traced still shows its attempts: each one starts its own trace, and Bullship finds them by job id.

Behind a reverse proxy, let /otlp/ through to Bullship as well as the app’s own paths. Apps inside the same network can send to Bullship directly, such as http://bullship:3200/otlp.

One row per span on a shared time axis: the request at the top, then the job’s Added span and one Attempt per run with the calls made inside it, and the wait before each attempt. Other jobs added in the same request are left out. The call that failed in the latest attempt, or else the slowest, is selected, with its attributes and events below. Arrow keys move between spans.

BULLSHIP_TRACES_DAYS=7 # the default; 1 to 30
BULLSHIP_TRACES_MAX_MB=256 # the default; 16 to 10240

When traces.db reaches its size, the oldest traces go first. Spans of a trace wait up to 2 hours for a job’s BullMQ span and are dropped without one: when only the worker is traced, BullMQ sends the attempt’s span when it ends, so an attempt longer than that shows without its calls. Trace the producer too and they wait for nothing. SQLite’s write-ahead log adds a few MB.

Each request may be up to 4 MB, 16 MB unzipped, and up to 5,000 spans. A trace keeps up to 2,000 spans, a span 64 attributes and 16 events, and a value 2 KB (8 KB for a stack trace). Spans past a limit are reported back to the exporter as rejected, and spans older than the retention or more than an hour ahead are refused.

Redaction applies to span names, attributes, events and status messages before they are written, so hidden values never reach the disk. An attribute is hidden when its name or the last part of it is a hidden name: http.request.header.authorization with the default list. Values that are JSON, such as bullmq.job.result, are checked like job data, and other text like logs. Fields hidden later are hidden in spans already stored, too.

Receiving spans sends Redis no commands; a job page reads its trace from traces.db. One process kept about 50,000 spans a second, with the heap flat at 22 MB.