diff --git a/includes/javascript-crons-automatic-crons-instrumentation.mdx b/includes/javascript-crons-automatic-crons-instrumentation.mdx index 8386cb29182fdf..9c14cf1b79b928 100644 --- a/includes/javascript-crons-automatic-crons-instrumentation.mdx +++ b/includes/javascript-crons-automatic-crons-instrumentation.mdx @@ -81,6 +81,39 @@ cronWithCheckIn.schedule( ### Node Schedule +#### Monitor All Named Jobs + +Requires SDK version `11.5.0` or higher. + +We recommend adding `nodeScheduleIntegration`, which monitors every job created with `scheduleJob` that has a name: + +```JavaScript +Sentry.init({ + dsn: "___PUBLIC_DSN___", + integrations: [ + Sentry.nodeScheduleIntegration({ + excludeJobs: ["cleanup-temp-files", /^debug-/], // Optional. + }), + ], +}); +``` + +```JavaScript +import schedule from "node-schedule"; + +schedule.scheduleJob( + "daily-report", + { rule: "30 9 * * 1-5", tz: "Europe/Vienna" }, + sendReport +); +``` + +The monitor slug is the job name. Jobs without a name, and jobs that run once at a `Date`, aren't monitored. `excludeJobs` skips jobs whose name matches a string exactly or a regular expression. + +For cron strings, each check-in sends the schedule and time zone (your server's time zone if `tz` isn't set). Recurrence rules, and schedules that can't be expressed in the Crons schedule format (for example, a job that runs every 10 seconds), check in without a monitor config, so create those monitors in Sentry first. + +#### Monitor Specific Jobs + Requires SDK version `7.93.0` or higher. Use `Sentry.cron.instrumentNodeSchedule` to instrument the `schedule` export from the [`node-schedule`](https://www.npmjs.com/package/node-schedule) library. This returns an object with the same API as the original `schedule` export, but with the `scheduleJob` method instrumented. You can pass the name of the cron job as the first argument to the function. Currently this only supports cronstring as the second argument to `scheduleJob`. @@ -98,3 +131,5 @@ scheduleWithCheckIn.scheduleJob( } ); ``` + +`nodeScheduleIntegration` skips jobs created with `instrumentNodeSchedule`, so using both doesn't send duplicate check-ins.