Skip to content

feat: add BullMQ integration#355

Open
jrothrock wants to merge 2 commits into
masterfrom
feat/bullmq
Open

feat: add BullMQ integration#355
jrothrock wants to merge 2 commits into
masterfrom
feat/bullmq

Conversation

@jrothrock

@jrothrock jrothrock commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds Scout APM instrumentation for BullMQ Worker job processing via a require-time shim on Worker.prototype.callProcessJob.

What's instrumented

Each job processed by a BullMQ Worker is wrapped in a Scout transaction + span with the operation name Job/{jobName}. The following context is attached to every span:

Context key Value
queue BullMQ queue name
task_id BullMQ job ID
priority Job priority (or "unknown" if unset)
scout.job_queue_time_ns Time from job enqueue to processing start (nanoseconds)
error "true" if the processor throws

Implementation approach

The shim patches Worker.prototype.callProcessJob (BullMQ's internal method that dispatches a single job to the user-provided processor). This is the narrowest possible hook point — it fires once per job execution regardless of concurrency settings, and it's the right place to measure end-to-end job duration including any internal BullMQ overhead before the processor runs.

Changes

  • lib/integrations/bullmq.ts — new BullMQIntegration class
  • lib/integrations/index.ts — registers bullmq in KNOWN_PACKAGES and getIntegrationForPackage
  • lib/types/enum.ts — adds ScoutContextName.TaskId, ScoutContextName.Priority, and ScoutSpanOperation.BullMQJob
  • test/integrations/bullmq.e2e.ts — e2e tests covering span creation, queue/task_id/priority/queue_time context, and error flag

Test plan

  • Job/{name} span is created for each processed job
  • queue, task_id, priority, and scout.job_queue_time_ns context values are present and correct
  • error: "true" is set on the span when the processor throws
  • Integration is a no-op when Scout monitor is disabled (scout not set)
  • Manual verification: run node_test_apps bullmq demo app and confirm Job/ spans appear in Scout APM UI

🤖 Generated with Claude Code

jrothrock and others added 2 commits June 23, 2026 20:44
Instruments BullMQ Worker job processing with Scout APM spans. Each job
gets a Job/{name} span with queue, task_id, priority, and queue time
context. Error flag is set when the processor throws.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Required for the e2e test to compile — bullmq types are shipped by
the package itself so no @types/* entry is needed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant