Skip to content

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

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

wedamija wants to merge 12 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

Coverage Results 📊

✅ 134919 passed | ⏭️ 7393 skipped | Total: 142312 | Pass Rate: 94.81% | Execution Time: 434m 56s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +617
Passed Tests 📈 +558
Failed Tests —
Skipped Tests 📈 +59

All tests are passing successfully.

✅ Patch coverage is 95.39% (207 of 217 changed executable lines covered; target 80%).
Project statement coverage is 90.35% (up 0.04 percentage points from base (9e4ba4c) to head (eec709e)).

Changed files with executable lines (3)
File Patch coverage Changed executable lines
sentry_sdk/integrations/apscheduler.py 95.02% 191/201 covered; missed: 58, 120, 206, 248, 359, 361, 362, 363, 364, 365; partial branches: 57, 119, 201, 247, 354
sentry_sdk/crons/utils.py 100.00% 12/12 covered
sentry_sdk/integrations/arq.py 100.00% 4/4 covered
Coverage diff
@@            Coverage Diff             @@
##        master     #7840       +/-##
==========================================
+ Coverage    90.31%    90.35%    +0.04%
==========================================
  Files          203       204        +1
  Tracked lines     26880     27084      +204
  Branches     10042     10118       +76
==========================================
+ Hits         24276     24470      +194
- Misses        2604      2614       +10
- Partials      1517      1522        +5

Generated by Coverage 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>
@linear-code

linear-code Bot commented Oct 21, 2026

Copy link
Copy Markdown

PY-3033

# Conflicts:
#	scripts/populate_tox/package_dependencies.jsonl
#	scripts/populate_tox/releases.jsonl
Comment thread sentry_sdk/integrations/apscheduler.py Outdated
Sentry monitor schedules don't end, so a finite cron or interval trigger
would raise missed check-ins after its last run.
Move arq's timezone name logic into sentry_sdk.crons.utils and use it for
APScheduler too, so fixed-offset timezones with whole-hour offsets are
monitored with Etc/GMT names. tzlocal's "local" zone is rejected.
Jitter delays runs by up to that many seconds, so add it on top of Sentry's
default 1 minute check-in margin.
@wedamija
wedamija marked this pull request as ready for review October 22, 2026 18:58
@wedamija
wedamija requested a review from a team as a code owner October 22, 2026 18:58
@wedamija
wedamija requested a review from sentrivana October 22, 2026 18:58
Comment thread tests/integrations/apscheduler/test_apscheduler.py

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