javascript

Monitor BullMQ Background Jobs with AppSignal

Connor James

Connor James on

Monitor BullMQ Background Jobs with AppSignal

AppSignal's Node.js package now supports monitoring BullMQ jobs.

In this article, we'll demonstrate how easy it is to start monitoring BullMQ performance and what insights you can expect to see for your BullMQ jobs in AppSignal.

Setting Up BullMQ Monitoring

BullMQ is automatically instrumented in versions 3.4.5 and higher of AppSignal's Node.js package.

If you're new to AppSignal, you'll first need to install our Node.js package, whereas existing AppSignal customers just need to ensure their Node.js package is up-to-date.

Installing AppSignal

To start monitoring BullMQ jobs, you'll first need to create an AppSignal account (you can do a 30-day free trial). Then install AppSignal's Node.js package:

Node.js
npm install --save @appsignal/nodejs

Note: Make sure you're using version 3.4.5 or higher.

You'll then need a valid API key to configure, require, and initialize AppSignal. You can obtain your API key from your organization's API key page (found under Administration settings).

We recommend initializing AppSignal with a config file:

Node.js
// appsignal.cjs const { Appsignal } = require("@appsignal/nodejs"); new Appsignal({ active: true, name: "<YOUR APPLICATION NAME>", pushApiKey: "<YOUR API KEY>", });

Once configured, no further setup for BullMQ is required, as it's automatically instrumented by the AppSignal package.

Updating Your AppSignal Package

If you're already monitoring your Node.js app with AppSignal, update the AppSignal package to version 3.4.5 or higher. We recommend updating your package to the latest version:

Shell
npm update appsignal@latest

Monitoring BullMQ Jobs with AppSignal

Once you've successfully installed and configured AppSignal, you'll automatically receive:

  • Error reports from BullMQ workers
  • Calls to functions that enqueue BullMQ jobs (like Queue.add)
  • BullMQ worker performance samples

You can use these insights to help ensure BullMQ jobs are being enqueued and processed efficiently and to resolve problems proactively before they break your background jobs.

BullMQ Worker Error Reporting

AppSignal will automatically track and notify you when exceptions occur with your BullMQ workers, helping you find and fix errors before they negatively impact your application. Review errors in the Error issue list:

Screenshot of AppSignal errors

Here, we can quickly view, sort, and filter issues based on important, contextual information:

  • Action name and error type: The name of the route/function where the error occurred and the name of the error type.
  • Status: The state (open, in progress, closed) and severity of the issue.
  • In deploy: How many times the error has occurred in the current latest deployment.
  • Total: The total count of error occurrences.
  • Last: How long it has been since the error last occurred.

When inspecting an error, we get a quick overview of the error and the end of its backtrace. From here, we can inspect individual error samples, filter errors based on deployments, inspect a full backtrace, and view trends:

Screenshot of AppSignal error overview

Monitoring BullMQ Job Performance

To help you understand how AppSignal tracks BullMQ job performance, we'll deliberately create a slow BullMQ background job.

In the following function, we'll send a message with BullMQ. To keep things simple, let's use a timeout function, forcing a request to take several seconds to complete.

ts
import { Worker, Queue } from "bullmq"; const worker = new Worker("slow_jobs", async (job: Job) => { console.log(`Processing a job that I made deliberately slow for the blog...`); // Let's use setTimeout to slow things down await new Promise((resolve) => setTimeout(resolve, 3000)); console.log(`Job says ${job.data.superSecretMessage}!`); }); const queue = new Queue("slow_jobs"); await queue.add("very_slow_job", { superSecretMessage: "Stroopwafels are the future.", });

This slow job will raise a performance issue in AppSignal. We can then review it in the Performance issue list:

Screenshot of AppSignal performance incidents

Here, we can quickly view, sort, and filter issues based on:

  • Action name: The name of the route/function where the performance incident took place.
  • Status: The state (open, in progress, closed) and severity of the issue.
  • Mean response time: The mean response time of all occurrences of the issue.
  • Throughput: The throughput of an issue's occurrences.
  • Impact: The impact an issue is having on overall performance.

Each issue gives us a clear overview of information, such as performance trends, performance in the last deploys, and samples. Samples are recorded each time a performance incident occurs:

Screenshot of AppSignal performance samples

Each occurrence gives us event-level insights into our performance incident. The Event Timeline makes it easy for us to understand which events in our request are causing performance issues.

Of course, in our case, we've deliberately slowed down our BullMQ job, so it's not a surprise to see that taking up the most time in our Event Timeline:

Screenshot of AppSignal event timeline

In a real-life scenario, these insights can help us see which background jobs are underperformant and which processes inside of those requests are the likely root cause, such as a large database query or slow API request.

Ready to Start Monitoring BullMQ with AppSignal?

In this post, we've shown you how to monitor the performance of BullMQ jobs using AppSignal. Read our BullMQ monitoring page and BullMQ docs for more information.

Still have some questions about AppSignal or monitoring your Node.js app? Send us an email. Our team is always on hand to help.

Connor James

Connor James

Official technical writer at AppSignal. Podcast addict who loves cannoli so much that he's considering changing his name to Connoli. He thinks there's a `u` in color. You might find him on the mic, on the stage, or lying on the sofa when he's off Documentation Duty.

All articles by Connor James

Become our next author!

Find out more

AppSignal monitors your apps

AppSignal provides insights for Ruby, Rails, Elixir, Phoenix, Node.js, Express and many other frameworks and libraries. We are located in beautiful Amsterdam. We love stroopwafels. If you do too, let us know. We might send you some!

Discover AppSignal
AppSignal monitors your apps