Sentry Cron Monitoring support #855

Open
opened 2024-04-22 10:01:20 +00:00 by SCjona · 3 comments

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_CRONS in the Sentry docs) in the borgmatic config and borgmatic should send the correct HTTP requests.

I tried implementing this with hooks (before_everything => send status=in_progress, on_error => send status=error and after_everything => send status=ok), which works fine for the success case (before_everything and after_everything is run), but in the error case it will run all three hooks and after_everything will cause the monitoring status to switch from error to ok. So alternatively I would like to request an on_success hook.

### 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_CRONS` in the Sentry docs) in the borgmatic config and borgmatic should send the correct HTTP requests. I tried implementing this with hooks (`before_everything` => send `status=in_progress`, `on_error` => send `status=error` and `after_everything` => send `status=ok`), which works fine for the success case (`before_everything` and `after_everything` is run), but in the error case it will run all three hooks and `after_everything` will cause the monitoring status to switch from `error` to `ok`. So alternatively I would like to request an `on_success` hook.
Owner

Thanks for filing this. Sentry support seems like a reasonable addition to borgmatic. But just to confirm, should the monitoring URL (SENTRY_CRONS from the docs you linked) be the same value as SENTRY_DSN, provided when creating a cron in Sentry?

And yeah, I would not recommend using before_everything/after_everything for sending monitoring pings, because after_everything runs even if an error occurs during the backup. (before_actions/after_actions may make more sense for this.)

Thanks for filing this. Sentry support seems like a reasonable addition to borgmatic. But just to confirm, should the monitoring URL (`SENTRY_CRONS` from the docs you linked) be the same value as `SENTRY_DSN`, provided when creating a cron in Sentry? And yeah, I would not recommend using `before_everything`/`after_everything` for sending monitoring pings, because `after_everything` runs even if an error occurs during the backup. (`before_actions`/`after_actions` may make more sense for this.)
Author

SENTRY_DSN is 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/2
SENTRY_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_CRONS is basically just the info in SENTRY_DSN combined with the Cron monitor name (called monitor slug in 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/
Where to find the monitor slug =>
image (bottom right in image => 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/

`SENTRY_DSN` is 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/2` `SENTRY_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_CRONS` is basically just the info in `SENTRY_DSN` combined with the Cron monitor name (called `monitor slug` in 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/ Where to find the monitor slug => ![image](/attachments/0d7d12b6-a91e-47b8-895e-f074b2db3e0c) (bottom right in image => `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](https://docs.sentry.io/platforms/python/)) 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/
Author

Also thank you for the hint with before_actions / after_actions. I got the cron monitoring setup working with before_actions => in_progress, on_error => error and after_actions => ok.

Also thank you for the hint with `before_actions` / `after_actions`. I got the cron monitoring setup working with `before_actions` => `in_progress`, `on_error` => `error` and `after_actions` => `ok`.
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: borgmatic-collective/borgmatic#855
No description provided.