At work we have a Sentry subscription which we use primarily for issue tracking
but recently I noticed the “Crons” entry in the sidebar and decided to give it
a try as we have a bunch of Nomad periodic jobs that aren’t exactly easy
to monitor with the Nomad WUI.
For context, our periodic jobs are basically invocations of
bundle exec rake <task> commands, so each task is running within a ruby
process and Sentry provides an easy to use API via their SDK.
The “Set Up Crons” document is straightforward and easy to follow. Given we’re
not using Sidekiq we couldn’t just include their modules and call it a day.
Instead we used the “Manual Setup” approach but it quickly became a repetitive
task to do a check-in for every job.
Upserting Cron Monitors
We already have a YAML file used to provision the nomad jobs with a cron
schedule, command and per-environment resources. We added a few more properties
to support “upsert” easily:
slug: used to identify Sentry monitors
max_runtime: to let Sentry know how long the job is expected to run
checkin_margin: we trust Nomad to spin-up the job on time but it doesn’t
hurt to add this measure.
So the YAML file ended up looking like the following:
And with this in place, we fully took advantage of Sentry’s capture_check_in
method:
And with this in place, we got a nice UI informing us if something isn’t right
at a glance.
Additionally, whenever an error is raised from a periodic job, it’s
automatically linked from the monitor page to a Sentry issue with the relevant
context at hand. Great product integration!