diff --git a/includes/javascript-crons-automatic-crons-instrumentation.mdx b/includes/javascript-crons-automatic-crons-instrumentation.mdx index 8b78d165e0cf2..a78e57351965c 100644 --- a/includes/javascript-crons-automatic-crons-instrumentation.mdx +++ b/includes/javascript-crons-automatic-crons-instrumentation.mdx @@ -27,6 +27,38 @@ const job = CronJobWithCheckIn.from({ ### Node Cron +#### Monitor All Named Tasks + +Requires SDK version `11.9.0` or higher. + +We recommend adding `nodeCronIntegration`, which monitors every task that has a `name`, without changing how you import `node-cron`: + +```JavaScript +Sentry.init({ + dsn: "___PUBLIC_DSN___", + integrations: [ + Sentry.nodeCronIntegration({ + excludeJobs: ["cleanup-temp-files", /^debug-/], // Optional. + }), + ], +}); +``` + +```JavaScript +import cron from "node-cron"; + +cron.schedule("0 9 * * 1-5", sendReport, { + name: "daily-report", + timezone: "Europe/Vienna", +}); +``` + +The monitor slug is the task's `name`. Tasks without a `name` aren't monitored. `excludeJobs` skips tasks whose name matches a string exactly or a regular expression. + +Each check-in sends the task's schedule and time zone (your server's time zone if `timezone` isn't set). Schedules that can't be expressed in the Crons schedule format (for example, a task that runs every 10 seconds) check in without a monitor config, so create those monitors in Sentry first. + +#### Monitor Specific Tasks + Requires SDK version `7.92.0` or higher. Use `Sentry.cron.instrumentNodeCron` to instrument the `cron` export from the [`node-cron`](https://www.npmjs.com/package/node-cron) library. This returns an object with the same API as the original `cron` export, but with the `schedule` method instrumented. You can pass the name of the cron monitor and an optional time zone as part of the third options argument to the function. @@ -45,6 +77,8 @@ cronWithCheckIn.schedule( ); ``` +`nodeCronIntegration` skips tasks created with `instrumentNodeCron`, so using both doesn't send duplicate check-ins. + ### Node Schedule Requires SDK version `7.93.0` or higher.