---
title: "Crons"
description: "Sentry Crons allows you to monitor the uptime and performance of any scheduled, recurring job in your application using the Sentry JavaScript SDK."
url: https://docs.sentry.io/platforms/javascript/guides/sveltekit/crons/
---

# Set Up Crons for SvelteKit

Once implemented, it'll allow you to get alerts and metrics to help you solve errors, detect timeouts, and prevent disruptions to your service.

## [Requirements](https://docs.sentry.io/platforms/javascript/guides/sveltekit/crons.md#requirements)

* Use our [getting started](https://docs.sentry.io/platforms/javascript/guides/sveltekit.md) guide to install and configure the Sentry SDK (version `7.51.1` or newer) for your recurring job.
* Send a monitor configuration from your code as shown below, and Sentry creates the monitor on the first check-in. You can also [create the monitor in Sentry](https://sentry.io/issues/alerts/new/crons/) instead.

Cron monitoring is only supported in SvelteKit server-side

## [Automatic Crons Instrumentation](https://docs.sentry.io/platforms/javascript/guides/sveltekit/crons.md#automatic-crons-instrumentation)

If you're using the [`cron`](https://www.npmjs.com/package/cron), [`node-cron`](https://www.npmjs.com/package/node-cron) or [`node-schedule`](https://www.npmjs.com/package/node-schedule) libraries to run your periodic tasks, you can use our integrations or the instrumentation functions in the `Sentry.cron` export to monitor your cron jobs. They send the job's schedule with each check-in, so Sentry creates the monitor for you.

### [Cron](https://docs.sentry.io/platforms/javascript/guides/sveltekit/crons.md#cron)

#### [Monitor All Named Jobs](https://docs.sentry.io/platforms/javascript/guides/sveltekit/crons.md#monitor-all-named-jobs)

Requires SDK version `11.11.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: "https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
  integrations: [
    Sentry.cronJobIntegration({
      excludeJobs: ["cleanup-temp-files", /^debug-/], // Optional.
    }),
  ],
});
```

*Other available variations of the above snippet: JavaScript*

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). These jobs send no check-ins, and the SDK doesn't warn you about them:

* Schedules that run more often than once a minute, such as every 10 seconds.
* Jobs with a `utcOffset`, or a `timeZone` that isn't an IANA name such as `America/Los_Angeles`.
* A `*/n` or full-range day field (such as `1-31` or `sun-sat`) combined with a restricted other day field, such as `0 0 9 */2 * 1`.
* A day of month that none of the selected months have, combined with a day of week, such as `0 0 9 31 2 1`.

Calling `setTime` on a job updates the schedule it sends. If the new time is one of the schedules above, or a date, the job stops sending check-ins.

To monitor one of these jobs, create the monitor in Sentry first and wrap the job's `onTick` function with [`Sentry.withMonitor`](https://docs.sentry.io/platforms/javascript/guides/sveltekit/crons.md#job-monitoring).

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

#### [Migrate From `instrumentCron`](https://docs.sentry.io/platforms/javascript/guides/sveltekit/crons.md#migrate-from-instrumentcron)

`Sentry.cron.instrumentCron` is deprecated. To move to `cronJobIntegration`:

1. Upgrade `cron` to version `4.3.0` or higher.
2. Add `cronJobIntegration` to `Sentry.init`, as shown above.
3. Remove the `instrumentCron` wrapper, and set each job's `name` to the monitor slug you passed to `instrumentCron`, so check-ins keep going to the same monitor.

Before:

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

const CronJobWithCheckIn = Sentry.cron.instrumentCron(CronJob, "my-cron-job");

CronJobWithCheckIn.from({
  cronTime: "* * * * *",
  onTick: () => {
    console.log("You will see this message every minute");
  },
});
```

After:

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

CronJob.from({
  name: "my-cron-job",
  cronTime: "* * * * *",
  onTick: () => {
    console.log("You will see this message every minute");
  },
});
```

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

### [Node Cron](https://docs.sentry.io/platforms/javascript/guides/sveltekit/crons.md#node-cron)

#### [Monitor All Named Tasks](https://docs.sentry.io/platforms/javascript/guides/sveltekit/crons.md#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: "https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
  integrations: [
    Sentry.nodeCronIntegration({
      excludeJobs: ["cleanup-temp-files", /^debug-/], // Optional.
    }),
  ],
});
```

*Other available variations of the above snippet: JavaScript*

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). Tasks whose schedule can't be expressed in the Crons schedule format send no check-ins, and the SDK doesn't warn you about them. These include:

* Schedules that run more often than once a minute, such as every 10 seconds.
* A `timezone` that isn't an IANA name such as `America/Los_Angeles`.
* Schedules that limit both the day of month and the day of week, unless one of them starts with `*`, such as `0 9 1-7 * 1`. `node-cron` runs these when both fields match, and Crons when either does.
* Ranges that wrap around, such as `22-2` in the hour field.
* On `node-cron` before 4.6, weekday ranges that end on Sunday, such as `sat-sun` or `1-7`, and steps without a range, such as `5/10`.
* On `node-cron` 3, steps that don't start on a multiple of the step, such as `*/2` in the day-of-month or month field.

To monitor one of these tasks, create the monitor in Sentry first and wrap the task's function with [`Sentry.withMonitor`](https://docs.sentry.io/platforms/javascript/guides/sveltekit/crons.md#job-monitoring).

#### [Monitor Specific Tasks](https://docs.sentry.io/platforms/javascript/guides/sveltekit/crons.md#monitor-specific-tasks)

Requires SDK version `7.92.0` or higher.

`Sentry.cron.instrumentNodeCron` is deprecated; use `nodeCronIntegration` instead. `instrumentNodeCron` can't tell which `node-cron` version you're on, so on `node-cron` 4, tasks with a day-of-month or month step such as `*/2` don't create a monitor automatically. Unlike `instrumentNodeCron`, the integration monitors every named task unless `excludeJobs` skips it, and it starts a new trace for each run.

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.

```JavaScript
import cron from "node-cron";

const cronWithCheckIn = Sentry.cron.instrumentNodeCron(cron);

cronWithCheckIn.schedule(
  "* * * * *",
  () => {
    console.log("running a task every minute");
  },
  { name: "my-cron-job" }
);
```

`nodeCronIntegration` skips tasks created with `instrumentNodeCron`, so using both doesn't send duplicate check-ins.

### [Node Schedule](https://docs.sentry.io/platforms/javascript/guides/sveltekit/crons.md#node-schedule)

#### [Monitor All Named Jobs](https://docs.sentry.io/platforms/javascript/guides/sveltekit/crons.md#monitor-all-named-jobs-1)

Requires SDK version `11.11.0` or higher.

We recommend adding `nodeScheduleIntegration`, which monitors every job that has a name, whether you create it with `scheduleJob` or `new schedule.Job()`:

```JavaScript
Sentry.init({
  dsn: "https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
  integrations: [
    Sentry.nodeScheduleIntegration({
      excludeJobs: ["cleanup-temp-files", /^debug-/], // Optional.
    }),
  ],
});
```

*Other available variations of the above snippet: JavaScript*

The monitor slug is the job name. Jobs without a name, and jobs that run once (at a `Date`, a timestamp or a date string), 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). These jobs send no check-ins, and the SDK doesn't warn you about them:

* Jobs scheduled with a recurrence rule, such as a `RecurrenceRule` or `{ hour: 9, minute: 30 }`, or with a `start` or `end`.
* Schedules that run more often than once a minute, such as every 10 seconds.
* A `tz` that isn't an IANA name such as `America/Los_Angeles`.
* Fields that use `?`, such as `0 9 ? * 1`.
* Day fields that `node-schedule` and Crons read differently: a `*/n` day of month combined with a day of week, such as `0 9 */2 * 1`, a day of month with 29 or more days combined with a day of week, such as `0 9 1-31 * 1`, or `#` combined with a day of month.

`job.reschedule(spec)` updates the schedule the job sends. A job stops sending check-ins if it's rescheduled to one of the specs above, or if you call `job.schedule(spec)` again while it still has runs pending, because `node-schedule` then adds the new runs to the old ones instead of replacing them.

To monitor one of these jobs, create the monitor in Sentry first and use `instrumentNodeSchedule`, as described below, or wrap the job's function with [`Sentry.withMonitor`](https://docs.sentry.io/platforms/javascript/guides/sveltekit/crons.md#job-monitoring).

#### [Monitor Specific Jobs](https://docs.sentry.io/platforms/javascript/guides/sveltekit/crons.md#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`. If Crons can't express the schedule, `instrumentNodeSchedule` still sends check-ins, without a schedule, to a monitor you create in Sentry.

```JavaScript
import * as schedule from "node-schedule";

const scheduleWithCheckIn = Sentry.cron.instrumentNodeSchedule(schedule);

scheduleWithCheckIn.scheduleJob(
  "my-cron-job",
  "* * * * *",
  () => {
    console.log("running a task every minute");
  }
);
```

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

## [Job Monitoring](https://docs.sentry.io/platforms/javascript/guides/sveltekit/crons.md#job-monitoring)

Use the `Sentry.withMonitor()` API to monitor a callback and notify you if your periodic task is missed (or doesn't start when expected), if it fails due to a problem in the runtime (such as an error), or if it fails by exceeding its maximum runtime.

`Sentry.withMonitor()` requires SDK version `7.76.0`.

Pass a monitor configuration as the third argument so Sentry creates or updates the monitor from your code:

```javascript
Sentry.withMonitor(
  "<monitor-slug>",
  () => {
    // Execute your scheduled task here...
  },
  {
    schedule: { type: "crontab", value: "0 * * * *" },
  },
);
```

If the monitor already exists in Sentry, the configuration is optional. See [Upserting Cron Monitors](https://docs.sentry.io/platforms/javascript/guides/sveltekit/crons.md#upserting-cron-monitors) for all configuration options.

`Sentry.withMonitor()` does not create new a trace. Events and errors that occur within the monitored callback will be associated with the current trace context.

If you are using an SDK version prior to `7.76.0`, you can use the `Sentry.captureCheckIn()` API documented below.

## [Check-Ins](https://docs.sentry.io/platforms/javascript/guides/sveltekit/crons.md#check-ins)

Check-in monitoring allows you to track a job's progress by completing two check-ins: one at the start of your job and another at the end of your job. This two-step process allows Sentry to notify you if your job didn't start when expected (missed) or if it exceeded its maximum runtime (failed).

```javascript
// 🟡 Notify Sentry your job is running:
const checkInId = Sentry.captureCheckIn({
  monitorSlug: "<monitor-slug>",
  status: "in_progress",
});

// Execute your scheduled task here...

// 🟢 Notify Sentry your job has completed successfully:
Sentry.captureCheckIn({
  // Make sure this variable is named `checkInId`
  checkInId,
  monitorSlug: "<monitor-slug>",
  status: "ok",
});
```

If your job execution fails, you can notify Sentry about the failure:

```javascript
// 🔴 Notify Sentry your job has failed:
Sentry.captureCheckIn({
  // Make sure this variable is named `checkInId`
  checkInId,
  monitorSlug: "<monitor-slug>",
  status: "error",
});
```

## [Heartbeat](https://docs.sentry.io/platforms/javascript/guides/sveltekit/crons.md#heartbeat)

Heartbeat monitoring notifies Sentry of a job's status through one check-in. This setup will only notify you if your job didn't start when expected (missed). If you need to track a job to see if it exceeded its maximum runtime (failed), use check-ins instead.

```javascript
// Execute your scheduled task...

// 🟢 Notify Sentry your job completed successfully:
Sentry.captureCheckIn({
  monitorSlug: "<monitor-slug>",
  status: "ok",
});
```

If your job execution fails, you can:

```javascript
// 🔴 Notify Sentry your job has failed:
Sentry.captureCheckIn({
  monitorSlug: "<monitor-slug>",
  status: "error",
});
```

## [Upserting Cron Monitors](https://docs.sentry.io/platforms/javascript/guides/sveltekit/crons.md#upserting-cron-monitors)

You can create and update your Monitors programmatically with code rather than [creating and configuring them in Sentry.io](https://sentry.io/issues/alerts/new/crons/).

To create/update a monitor, use `Sentry.withMonitor()` and pass in your monitor configuration as a third parameter:

```javascript
const monitorConfig = {
  schedule: {
    type: "crontab",
    value: "* * * * *",
  },
  checkinMargin: 2, // In minutes. Optional.
  maxRuntime: 10, // In minutes. Optional.
  timezone: "America/Los_Angeles", // Optional.
};

Sentry.withMonitor(
  "<monitor-slug>",
  () => {
    // Execute your scheduled task here...
  },
  monitorConfig,
);
```

To configure the monitor's check-ins, use `Sentry.captureCheckIn()` and pass in your monitor configuration as a second parameter:

```javascript
const monitorConfig = {
  schedule: {
    type: "crontab",
    value: "* * * * *",
  },
  checkinMargin: 2, // In minutes. Optional.
  maxRuntime: 10, // In minutes. Optional.
  timezone: "America/Los_Angeles", // Optional.
};

// 🟡 Notify Sentry your job is running:
const checkInId = Sentry.captureCheckIn(
  {
    monitorSlug: "<monitor-slug>",
    status: "in_progress",
  },
  monitorConfig,
);

// Execute your scheduled task here...

// 🟢 Notify Sentry your job has completed successfully:
Sentry.captureCheckIn(
  {
    // Make sure this variable is named `checkInId`
    checkInId,
    monitorSlug: "<monitor-slug>",
    status: "ok",
  },
  monitorConfig,
);
```

### [Monitor Configuration Properties](https://docs.sentry.io/platforms/javascript/guides/sveltekit/crons.md#monitor-configuration-properties)

The following are available monitor configuration properties:

`schedule`:

The job's schedule:

The schedule representation for your monitor, either `crontab` or `interval`. The structure will vary depending on the type:

```json
{"type": "crontab", "value": "0 * * * *"}
{"type": "interval", "value": 2, "unit": "hour"}
```

`checkinMargin`:

The amount of time (in minutes) Sentry should wait for your check-in before it's considered missed ("grace period"). Optional.

We recommend that your check-in margin be less than or equal to your interval.

`maxRuntime`:

The amount of time (in minutes) your job is allowed to run before it's considered failed. The maximum is 10080 minutes (7 days). Optional.

`timezone`:

The `tz` where your job is running. This is usually your server's timezone, (such as `America/Los_Angeles`). See [list of tz database time zones](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones). Optional.

`node-cron` allows you to pass luxon timezones, but you have to convert them to an IANA timezone when using Sentry (for example, using `DateTime.local().zoneName`).

`failureIssueThreshold`:

*requires SDK version `8.7.0` or higher*

The number of consecutive failed check-ins required before an issue can be created. Optional.

`recoveryThreshold`:

*requires SDK version `8.7.0` or higher*

The number of consecutive successful check-ins required for an issue to be considered resolved. Optional.

## [Alerts](https://docs.sentry.io/platforms/javascript/guides/sveltekit/crons.md#alerts)

When your recurring job fails to check in (missed), runs beyond its configured maximum runtime (failed), or manually reports a failure, Sentry will create an error event with a tag to your monitor.

To receive alerts about these events:

1. Navigate to **Alerts** in the sidebar.
2. Create a new alert and select "Issues" under "Errors" as the alert type.
3. Configure your alert and define a filter match to use: `The event's tags match {key} {match} {value}`.

Example: `The event's tags match monitor.slug equals my-monitor-slug-here`

Learn more in [Alerts](https://docs.sentry.io/product/monitors-and-alerts/alerts.md).

## [Rate Limits](https://docs.sentry.io/platforms/javascript/guides/sveltekit/crons.md#rate-limits)

To prevent abuse and resource overuse, Crons limits check-ins to **6 per minute for each monitor environment**.

For example, if you have a monitor called "database-backup" with two environments:

* `database-backup` in environment `production` can send up to 6 check-ins per minute
* `database-backup` in environment `staging` can also send up to 6 check-ins per minute
* Combined, they can send up to 12 check-ins per minute

You can verify if any check-ins are being dropped by visiting the [Usage Stats](https://docs.sentry.io/product/stats.md#usage-stats) page. To avoid dropped check-ins, ensure your monitors don't exceed the rate limit.

## Pages in this section

- [Troubleshooting](https://docs.sentry.io/platforms/javascript/guides/sveltekit/crons/troubleshooting.md)

---

Find other pages: [Sitemap](https://docs.sentry.io/sitemap.md) lists every page with a one-line summary, and [llms.txt](https://docs.sentry.io/llms.txt) gives an overview with guidance for agents.
