Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.5.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.
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