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 Python SDK (min v1.17.0) for your recurring job.
- Create and configure your first Monitor.
Job Monitoring
Use the Python SDK to monitor 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.
Note on Celery
If you're using Celery Beat to run your periodic tasks, have a look at our Celery Beat Auto Discovery documentation.
import sentry_sdk
from sentry_sdk.crons import monitor
# Add the @monitor decorator to your task
@monitor(monitor_slug='<monitor-slug>')
def tell_the_world(msg):
# Scheduled task here...
print(msg)
Connecting Errors to Cron Monitors
To link any exceptions captured during your job's lifecycle, use Sentry's context with your monitor slug.
sentry_sdk.set_context("monitor", {
"slug": "<monitor_slug>",
})
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:
- pypi:sentry-sdk
- Version:
- 1.25.1
- Repository:
- https://github.com/getsentry/sentry-python