Repository navigation
feat(huey): Add an option to monitor Huey periodic tasks - #8052
Conversation
Send check-ins around each run of a Huey periodic task when HueyIntegration(monitor_periodic_tasks=True) is set. Huey crontab() schedules are sent as the monitor config when Huey runs in UTC, so Sentry creates the monitor and keeps it in sync. Co-Authored-By: Claude <[email protected]>
Coverage Results 📊✅ 134017 passed | ⏭️ 7311 skipped | Total: 141328 | Pass Rate: 94.83% | Execution Time: 435m 22s 📊 Comparison with Base Branch
➖ Removed Tests (58)View removed tests
All tests are passing successfully. ✅ Patch coverage is 96.43% (54 of 56 changed executable lines covered; target 80%). Changed files with executable lines (1)
Coverage diff@@ Coverage Diff @@
## master #8052 +/-##
==========================================
+ Coverage 90.25% 90.28% +0.03%
==========================================
Files 202 202 —
Tracked lines 26660 26793 +133
Branches 9926 9994 +68
==========================================
+ Hits 24062 24189 +127
- Misses 2598 2604 +6
- Partials 1510 1516 +6Generated by Coverage Action |
| _CRONTAB_CODE = crontab().__code__ | ||
|
|
||
|
|
||
| def _get_closure_var(func: "Any", name: str) -> "Any": |
There was a problem hiding this comment.
Constructing the monitor from code inspection like this feels brittle. Is there any other way we can get to it, e.g. by monkeypatching something (the crontab func maybe? haven't looked into it so don't know if feasible)?
There was a problem hiding this comment.
I looked into this with Claude for a while and it seems like it's pretty hard to do this via monkeypatching.
Huey doesn't have a public schedule object. crontab() keeps the parsed values in a closure and returns a plain timestamp -> bool function. Since most users import crontab before sentry_sdk.init(), any module where it's imported will have the original instead of the monkeypatched one.
It's definitely brittle if they change these internals. If they do, we will catch this in ci within a week since we bump to the latest Huey on a weekly basis.
I'm open to other options though if you have any thoughts on how to make this better
There was a problem hiding this comment.
Thanks for checking, I also briefly looked into it but didn't find a better way. Let's go with this then, and we'll monitor in the test matrix in CI.
`RetryTask`, `TaskLockedException` and `CancelExecution` aren't failures for Huey or for the integration's error capture, so they no longer mark the check-in as an error. Co-Authored-By: Claude <[email protected]>
Match the Celery beat integration: skip periodic tasks whose schedule can't be expressed as a Sentry Crons monitor config instead of sending check-ins without one. Co-Authored-By: Claude <[email protected]>
Match Celery, which marks a retried beat task's check-in as an error. Co-Authored-By: Claude <[email protected]>
Part of a series adding automatic Crons monitoring for the most-used job schedulers in each SDK. Check-ins for a monitor that doesn't exist yet are dropped, so today each monitor has to be created by hand with its schedule copied from the code. Sending the job's schedule as the monitor config lets Sentry create the monitor and keep it in sync.
This adds
monitor_periodic_taskstoHueyIntegration, matching Celery'smonitor_beat_tasks. When it's on, each@huey.periodic_taskrun sends check-ins with itscrontab(...)schedule in UTC, so Sentry creates the monitor on the first run. The slug is the task name. It's off by default, and regular tasks are unaffected.Tasks aren't monitored when they use a custom
validate_datetime, restrict bothdayandday_of_week, or run on a Huey instance withutc=False.Docs: getsentry/sentry-docs#20057