Set Up Crons

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

Job Monitoring

Standard job frameworks such as ActiveJob and Sidekiq with a perform method can use the Sentry::Cron::MonitorCheckIns mixin module to automatically capture check-ins.

Copied
class ExampleJob < ApplicationJob
  include Sentry::Cron::MonitorCheckIns

  sentry_monitor_check_ins

  def perform(*args)
    # do stuff
  end
end

You can pass in optional attributes to sentry_monitor_check_ins as follows.

Copied
# slug defaults to the job class name
sentry_monitor_check_ins slug: 'custom_slug'

# define the monitor config with an interval
sentry_monitor_check_ins monitor_config: Sentry::Cron::MonitorConfig.from_interval(1, :minute)

# define the monitor config with a crontab
sentry_monitor_check_ins monitor_config: Sentry::Cron::MonitorConfig.from_crontab('5 * * * *')

Manual Setup

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).

Copied
check_in_id = Sentry.capture_check_in('<monitor-slug>', :in_progress)
# Execute your scheduled task here...
Sentry.capture_check_in('<monitor-slug>', :ok, check_in_id: check_in_id)

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

Copied
Sentry.capture_check_in('<monitor-slug>', :error, check_in_id: check_in_id)

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.

Copied
Sentry.capture_check_in('<monitor-slug>', :ok)

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

Copied
Sentry.capture_check_in('<monitor-slug>', :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:

  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

Cron completed alert filter

Learn more in Issue Alert Configuration.

Help improve this content
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").