diff --git a/includes/javascript-crons-automatic-crons-instrumentation.mdx b/includes/javascript-crons-automatic-crons-instrumentation.mdx index 8b78d165e0cf2c..5d3f267b15eb02 100644 --- a/includes/javascript-crons-automatic-crons-instrumentation.mdx +++ b/includes/javascript-crons-automatic-crons-instrumentation.mdx @@ -1,4 +1,4 @@ -If you're using the [`cron`](https://www.npmjs.com/package/cron), [`node-cron`](https://www.npmjs.com/package/node-cron) or [`node-schedule`](https://www.npmjs.com/package/node-schedule) libraries to run your periodic tasks, you can use our instrumentation functions in the `Sentry.cron` export to monitor your cron jobs. These functions send the job's schedule with each check-in, so Sentry creates the monitor for you. +If you're using the [`cron`](https://www.npmjs.com/package/cron), [`node-cron`](https://www.npmjs.com/package/node-cron) or [`node-schedule`](https://www.npmjs.com/package/node-schedule) libraries to run your periodic tasks, or [BullMQ](https://www.npmjs.com/package/bullmq) job schedulers, you can use our instrumentation functions in the `Sentry.cron` export to monitor your cron jobs. These functions send the job's schedule with each check-in, so Sentry creates the monitor for you. ### Cron @@ -64,3 +64,32 @@ scheduleWithCheckIn.scheduleJob( } ); ``` + +### BullMQ + + + +BullMQ support ships in the next release of `@sentry/node`. + + + +Use `Sentry.cron.instrumentBullMQWorker` to send check-ins for every job a BullMQ `Worker` runs from a [job scheduler](https://docs.bullmq.io/guide/job-schedulers). The job scheduler ID is the monitor slug, and the scheduler's `pattern` or `every` is sent as the monitor schedule. Jobs that weren't created by a job scheduler aren't monitored. + +```JavaScript +import { Queue, Worker } from "bullmq"; + +const queue = new Queue("reports", { connection }); +await queue.upsertJobScheduler( + "daily-report", + { pattern: "0 9 * * 1-5", tz: "Europe/Vienna" }, + { name: "report" } +); + +const worker = new Worker("reports", processor, { connection }); +Sentry.cron.instrumentBullMQWorker(worker, { + // job scheduler IDs or regular expressions to skip + excludeJobSchedulers: ["cache-warmup", /^tmp-/], +}); +``` + +Sentry creates the monitor from `pattern` schedules and from `every` intervals that are a whole number of minutes. For schedules that can't be expressed in the Crons schedule format (for example, a job that runs every 10 seconds), schedulers with a `limit` or `endDate`, and time zones given as an offset like `UTC+5` rather than an IANA name like `Europe/Vienna`, the SDK sends check-ins without a monitor config, and you need to create the monitor in Sentry with the same slug. Repeatable jobs added with `queue.add` and the `repeat` option aren't monitored.