Skip to content
39 changes: 39 additions & 0 deletions includes/javascript-crons-automatic-crons-instrumentation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,43 @@ If you're using the [`cron`](https://www.npmjs.com/package/cron), [`node-cron`](

### Cron

#### Monitor All Named Jobs

Requires SDK version `11.9.0` or higher and `cron` version `4.3.0` or higher.

We recommend adding `cronJobIntegration`, which monitors every job that has a `name`:

```JavaScript
Sentry.init({
dsn: "___PUBLIC_DSN___",
integrations: [
Sentry.cronJobIntegration({
excludeJobs: ["cleanup-temp-files", /^debug-/], // Optional.
}),
],
});
```

```JavaScript
import { CronJob } from "cron";

CronJob.from({
name: "daily-report",
cronTime: "0 30 9 * * 1-5",
timeZone: "Europe/Vienna",
onTick: sendReport,
start: true,
});
```

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.

Each check-in sends the 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 job that runs every 10 seconds), and jobs with a `utcOffset`, aren't monitored.

In NestJS, use the Nest integration's `monitorCronJobs` option instead, because `@nestjs/schedule` runs `@Cron()` methods as named `cron` jobs.

#### Monitor Specific Jobs

Requires SDK version `7.92.0` or higher.

Use `Sentry.cron.instrumentCron` to instrument the `CronJob` constructor or `CronJob.from` method in the [`cron`](https://www.npmjs.com/package/cron) library. Pass the name of the cron monitor as a second argument to the function.
Expand All @@ -25,6 +62,8 @@ const job = CronJobWithCheckIn.from({
});
```

`cronJobIntegration` skips jobs created with `instrumentCron`, so using both doesn't send duplicate check-ins.

### Node Cron

#### Monitor All Named Tasks
Expand Down
Loading