Skip to content
35 changes: 35 additions & 0 deletions includes/javascript-crons-automatic-crons-instrumentation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,39 @@ cronWithCheckIn.schedule(

### Node Schedule

#### Monitor All Named Jobs

Requires SDK version `11.9.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, rules with a `start` or `end`, and schedules that can't be expressed in the Crons schedule format (for example, a job that runs every 10 seconds) aren't monitored.

#### 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`.
Expand All @@ -98,3 +131,5 @@ scheduleWithCheckIn.scheduleJob(
}
);
```

`nodeScheduleIntegration` skips jobs created with `instrumentNodeSchedule`, so using both doesn't send duplicate check-ins.
Loading