Sentry Cron Monitoring support #855
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What I'd like to do and why
I'd like to use Sentry Cron Monitoring to monitor my backups.
See the documentation here: https://docs.sentry.io/product/crons/getting-started/http/#check-ins-recommended
Other notes / implementation ideas
You'd configure the monitoring URL (variable
SENTRY_CRONSin the Sentry docs) in the borgmatic config and borgmatic should send the correct HTTP requests.I tried implementing this with hooks (
before_everything=> sendstatus=in_progress,on_error=> sendstatus=errorandafter_everything=> sendstatus=ok), which works fine for the success case (before_everythingandafter_everythingis run), but in the error case it will run all three hooks andafter_everythingwill cause the monitoring status to switch fromerrortook. So alternatively I would like to request anon_successhook.Thanks for filing this. Sentry support seems like a reasonable addition to borgmatic. But just to confirm, should the monitoring URL (
SENTRY_CRONSfrom the docs you linked) be the same value asSENTRY_DSN, provided when creating a cron in Sentry?And yeah, I would not recommend using
before_everything/after_everythingfor sending monitoring pings, becauseafter_everythingruns even if an error occurs during the backup. (before_actions/after_actionsmay make more sense for this.)SENTRY_DSNis something else, it's basically just an project identifer used for error and performance reporting. They created special endpoints for cron monitoring.Example values:
SENTRY_DSN:https://<random-hex-token>@<sentry-host-name>/<project-id>=>https://ada43a0c496f5b2439866a6c20398628@sentry.hostname.tld/2SENTRY_CRONS:https://<sentry-host-name>/api/<project-id>/cron/<cron-name>/<hex-token-from-DSN>/=>https://sentry.hostname.tld/api/2/cron/my-backups/ada43a0c496f5b2439866a6c20398628/As you can see
SENTRY_CRONSis basically just the info inSENTRY_DSNcombined with the Cron monitor name (calledmonitor slugin Sentry UI). Might be easier to just require the users to configure those two as they are easily found in Sentry UI.Where to find the DSN => https://docs.sentry.io/product/sentry-basics/concepts/dsn-explainer/
(bottom right in image =>
Where to find the monitor slug =>
monitor slug)You could also consider doing a complete Sentry Integration, not just for the Cron monitoring part. You could report errors directly to Sentry and track performance (which backup step took how long for example) with it, however I'm not sure if adding a new dependency (Sentry Python SDK) is reasonable/acceptable for the project. It's probably overkill anyways.
Also FYI there is self-hosted sentry, pretty easy to set up if you know your way around Linux and Docker: https://develop.sentry.dev/self-hosted/
Also thank you for the hint with
before_actions/after_actions. I got the cron monitoring setup working withbefore_actions=>in_progress,on_error=>errorandafter_actions=>ok.Thanks for the clarification, and I'm glad to hear you have a work-around with
before_actions/after_actions!This is implemented in main and will be part of the next release! The documentation should be available online shortly: https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#sentry-hook
Here's the basic configuration I ended up going with, based on your suggestion:
I didn't do a "complete" Sentry integration; only the cron monitor portion is integrated.
Thanks for your patience here!
Released in borgmatic 1.9.7!