Skip to content

feat(apscheduler): Add cron monitoring for scheduled jobs - #7840

Draft
wedamija wants to merge 6 commits into
masterfrom
danf/apscheduler-crons
Draft

wedamija wants to merge 6 commits into
masterfrom
danf/apscheduler-crons

Conversation

@wedamija

@wedamija wedamija commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Description

Adds cron monitoring to a new APScheduler integration (3.3+), opt-in like CeleryIntegration(monitor_beat_tasks=True):

sentry_sdk.init(integrations=[APSchedulerIntegration(monitor_jobs=True)])

When a job is due, an in_progress check-in is sent with a monitor config built from its trigger, so Sentry creates the monitor on the first run; ok or error follows with the duration. CronTrigger and IntervalTrigger are supported. Triggers Sentry can't represent exactly, and one-off DateTrigger jobs, are not monitored, rather than sent with a schedule that would cause false missed-check-in alerts. The slug is the job id, or the job name when the id was generated; exclude_jobs skips jobs by regex.

Motivation

Check-ins for a monitor that doesn't exist yet are dropped, so APScheduler users have to create each monitor by hand and add check-in calls to every job. The schedule is already on the trigger, so the SDK can send it and monitors are created and kept in sync automatically.

Testing

tests/integrations/apscheduler, including thread pool, process pool and asyncio schedulers.

Docs: getsentry/sentry-docs#19786

Add an opt-in APSchedulerIntegration(monitor_jobs=True) for APScheduler 3.x.
When a job with a cron or interval trigger is submitted to its executor, send
an in_progress check-in with a monitor config derived from the trigger, so the
monitor is created on first run. A scheduler listener sends the ok/error
check-in when the run finishes or is missed.

The integration is not auto-enabled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Codecov Results 📊

✅ 133740 passed | ⏭️ 7239 skipped | Total: 140979 | Pass Rate: 94.87% | Execution Time: 451m 27s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +594
Passed Tests 📈 +578
Failed Tests 📉 -1
Skipped Tests 📈 +17

➖ Removed Tests (1)

View removed tests
  • test_cache_spans_decorator[True]
    • File: tests.integrations.django.test_cache_module

All tests are passing successfully.

✅ Patch coverage is 94.55%. Project has 2567 uncovered lines.
✅ Project coverage is 90.41%. Comparing base (6a4eb20) to head (14d3b3b).

Files with missing lines (1)
File Patch % Lines
sentry_sdk/integrations/apscheduler.py 94.37% ⚠️ 12 Missing and 5 partials
Coverage diff
@@            Coverage Diff             @@
##        master       #PR       +/-##
==========================================
+ Coverage    90.38%    90.41%    +0.03%
==========================================
  Files          202       204        +2
  Lines        26552     26772      +220
  Branches      9858      9936       +78
==========================================
+ Hits         23997     24205      +208
- Misses        2555      2567       +12
- Partials      1487      1492        +5

Generated by Codecov Action

Comment thread tests/integrations/apscheduler/test_apscheduler.py
wedamija and others added 2 commits October 2, 2026 15:53
Regenerating locally dropped cached releases of other packages. Restore them
and keep only the APScheduler entries.

Co-Authored-By: Claude <noreply@anthropic.com>
Move the APScheduler interval-to-schedule conversion into a private
helper in sentry_sdk.crons so other integrations can reuse it.

Co-Authored-By: Claude <noreply@anthropic.com>
Comment thread tests/integrations/apscheduler/test_apscheduler.py
wedamija and others added 3 commits October 2, 2026 17:40
Co-Authored-By: Claude <noreply@anthropic.com>
- Handle the Optional[str] check-in id that capture_checkin now returns.
- Send the monitor config only when the trigger's timezone is an IANA
  name. Sentry rejects names like "UTC+02:00", and without a timezone it
  would read the crontab as UTC.
- Open the check-ins only once the executor accepts the job, so runs
  skipped because of max_instances send none, instead of in_progress
  followed by error.
- Warn once per job when it has no explicit id and its name is used as
  the monitor slug.
- Say that only APScheduler 3.x is supported when the import fails.

Co-Authored-By: Claude <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant