Skip to content

Auto-upsert Sentry cron monitors for the tasks#42

Merged
codingjoe merged 10 commits intocodingjoe:mainfrom
amureki:autoinsert-sentry-monitors
Apr 23, 2026
Merged

Auto-upsert Sentry cron monitors for the tasks#42
codingjoe merged 10 commits intocodingjoe:mainfrom
amureki:autoinsert-sentry-monitors

Conversation

@amureki
Copy link
Copy Markdown
Contributor

@amureki amureki commented Apr 21, 2026

Hey 👋

This PR mirrors voiio/dramatiq-crontab#186

Sentry introduced an ability to automatically create cron monitors in case the monitor config is provided along with the payload:
https://docs.sentry.io/platforms/python/crons/#configuring-cron-monitors

In case we are positive that Sentry is used within the project, instead of simply sending the signal, we can upsert the config right away to reduce the amount of manual work.

Copilot AI review requested due to automatic review settings April 21, 2026 13:21
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.85%. Comparing base (0a31c4f) to head (07694b3).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #42      +/-   ##
==========================================
+ Coverage   98.59%   98.85%   +0.25%     
==========================================
  Files           5        6       +1     
  Lines         142      174      +32     
==========================================
+ Hits          140      172      +32     
  Misses          2        2              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for automatically upserting Sentry cron monitor configuration when sentry-sdk is available, reducing manual Sentry monitor setup for scheduled tasks.

Changes:

  • Build and attach monitor_config (schedule + timezone) when wrapping tasks with sentry_sdk.crons.monitor.
  • Add _monitor_config() helper to translate crontab strings and IntervalTrigger into Sentry cron config payloads.
  • Extend tests to validate monitor_config is passed for crontab and interval schedules.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
crontask/__init__.py Generates Sentry monitor configuration and passes it to monitor() when available.
tests/test_tasks.py Adds tests/fixture to validate Sentry monitor_config integration for cron + interval schedules.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_tasks.py Outdated
Comment thread crontask/__init__.py Outdated
Comment thread crontask/__init__.py Outdated
Copy link
Copy Markdown
Owner

@codingjoe codingjoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @amureki, let's make this spectecular!

Comment thread crontask/__init__.py Outdated
Comment thread crontask/__init__.py Outdated
Comment thread crontask/__init__.py Outdated
Comment thread crontask/__init__.py Outdated
Comment thread crontask/__init__.py Outdated
Comment thread crontask/__init__.py Outdated
Comment thread tests/test_tasks.py Outdated
Comment thread tests/test_tasks.py Outdated
@amureki amureki requested a review from codingjoe April 21, 2026 14:36
Copy link
Copy Markdown
Owner

@codingjoe codingjoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I previously missed something.

Comment thread crontask/__init__.py Outdated
@codingjoe codingjoe force-pushed the autoinsert-sentry-monitors branch from 96643ae to cdc34f6 Compare April 21, 2026 17:21
@codingjoe
Copy link
Copy Markdown
Owner

@amureki FYI: https://discord.com/channels/621778831602221064/1496192154702315560

Copy link
Copy Markdown
Owner

@codingjoe codingjoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amureki I chatted with sentry. This should be fine now. However, please be so kind and double check my amendment. Pretty cool idea. I stared working on something realed. Good things to come 😁

Copy link
Copy Markdown
Contributor Author

@amureki amureki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks for wrapping it up! LGTM

@codingjoe
Copy link
Copy Markdown
Owner

@amureki I thought about this while sleeping. I think we need to disable the sentry checking, if it's based on an unsupported trigger. So not only no upsert, but no checking. You shouldn't have a monitor on those anyway. Especially if they are sub-minute, this would result in crazy telemetry overhead. Thoughts?

@amureki
Copy link
Copy Markdown
Contributor Author

amureki commented Apr 22, 2026

@amureki I thought about this while sleeping. I think we need to disable the sentry checking, if it's based on an unsupported trigger. So not only no upsert, but no checking. You shouldn't have a monitor on those anyway. Especially if they are sub-minute, this would result in crazy telemetry overhead. Thoughts?

That probably would make sense, yes. But would you still want to have it in the same PR or separately?

@codingjoe
Copy link
Copy Markdown
Owner

Na, let's get it right now. @amureki what do you think?

Comment thread crontask/__init__.py
Comment thread crontask/__init__.py Outdated
Comment thread tests/contrib/test_sentry.py Outdated
Comment thread tests/contrib/test_sentry.py Outdated
codingjoe and others added 2 commits April 23, 2026 12:09
Co-authored-by: Rust Saiargaliev <hey@amureki.me>
@codingjoe codingjoe merged commit ae12a07 into codingjoe:main Apr 23, 2026
15 checks passed
@amureki amureki deleted the autoinsert-sentry-monitors branch April 23, 2026 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants