Skip to content
34 changes: 34 additions & 0 deletions includes/javascript-crons-automatic-crons-instrumentation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,38 @@ const job = CronJobWithCheckIn.from({

### Node Cron

#### Monitor All Named Tasks

Requires SDK version `11.11.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) aren't monitored.

#### 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.
Expand All @@ -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.
Expand Down
Loading