Set Up Crons
Sentry Crons allows you to monitor the uptime and performance of any scheduled, recurring job in your application.
Once implemented, it'll allow you to get alerts and metrics to help you solve errors, detect timeouts, and prevent disruptions to your service.
- Use our getting started guide to install and configure the Sentry Laravel SDK (min v3.3.1) for your recurring job.
Use the Laravel SDK to monitor and notify you if your scheduled 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.
To set up, add the sentryMonitor()
macro to the scheduled tasks defined in your app/Console/Kernel.php
file as shown below. (Please note, this will create a Cron monitor that will count against your quota.)
app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
$schedule->command('emails:send')
->everyHour()
->sentryMonitor(); // add this line
}
Tasks that use Laravel's between
, unlessBetween
, when
and skip
methods are currently not supported. For the best results, we recommend using Laravel's cron
method to define your schedule's frequency.
By default, the Laravel SDK will infer various parameters of your scheduled task. For greater control, we expose some optional parameters on the sentryMonitor()
macro.
app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
$schedule->command('emails:send')
->everyHour()
->sentryMonitor(
// Specify the slug of the job monitor in case of duplicate commands or if the monitor was created in the UI
monitorSlug: null,
// Check-in margin in minutes
checkInMargin: 5,
// Max runtime in minutes
maxRuntime: 15,
// In case you want to configure the job monitor exclusively in the UI, you can turn off sending the monitor config with the check-in.
// Passing a monitor-slug is required in this case.
updateMonitorConfig: false,
)
}
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.
Crons imposes a rate limit on check-ins to prevent abuse and resource overuse. Specifically, you can only send a maximum of 6 check-ins per minute per existing monitor environment. This limit is enforced on a per-project basis, meaning that the rate limit applies collectively to all monitor environments within a given project. You can check if any of your check-ins are being dropped in the Usage Stats page.
To avoid dropped check-ins, it is crucial to manage and distribute your check-ins efficiently within the rate limits. This will help maintain accurate monitoring and ensure that all critical check-ins are captured and processed.
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").