Set Up Crons
Important
Sentry Cron Monitoring is currently in open beta and subject to change. Help us make it better by letting us know what you think. Respond on GitHub or write to us at crons-feedback@sentry.io.
Sentry Crons allows you to monitor the uptime and performance of any scheduled, recurring job. 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
- Use our getting started guide to install and configure the Sentry SDK (version
7.51.1
or newer) for your recurring job. - Create and configure your first Monitor.
Check-Ins (Recommended)
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).
// 🟡 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({
checkInId,
monitorSlug: "<monitor-slug>",
status: "ok",
});
If your job execution fails, you can notify Sentry about the failure:
// 🔴 Notify Sentry your job has failed:
Sentry.captureCheckIn({
checkInId,
monitorSlug: "<monitor-slug>",
status: "error",
});
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.
// Execute your scheduled task...
// 🟢 Notify Sentry your job completed successfully:
Sentry.captureCheckIn({
monitorSlug: "<monitor-slug>",
status: "ok",
});
If your job execution fails, you can:
// 🔴 Notify Sentry your job has failed:
Sentry.captureCheckIn({
monitorSlug: "<monitor-slug>",
status: "error",
});
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:
- Navigate to Alerts in the sidebar.
- Create a new alert and select "Issues" under "Errors" as the alert type.
- 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 Issue Alert Configuration.
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) to suggesting an update ("yeah, this would be better").
- Package:
- npm:@sentry/node
- Version:
- 7.73.0
- Repository:
- https://github.com/getsentry/sentry-javascript