Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions docs/platforms/python/integrations/apscheduler/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
title: APScheduler
description: "Learn how to monitor APScheduler jobs with Sentry Crons."
---

The APScheduler integration monitors jobs scheduled with [APScheduler](https://apscheduler.readthedocs.io/en/3.x/) using [Sentry Crons](/product/monitors-and-alerts/monitors/crons/). You get alerted when a job doesn't run on time, fails, or runs too long.

<Alert>
This integration is available from the next SDK release after `2.71.0`.
</Alert>

## Install

Install `sentry-sdk` from PyPI:

```bash {tabTitle:pip}
pip install "sentry-sdk"
```

```bash {tabTitle:uv}
uv add "sentry-sdk"
```

## Configure

The integration isn't enabled automatically. Add `APSchedulerIntegration` with `monitor_jobs=True` in the process that runs the scheduler:

```python
import sentry_sdk
from sentry_sdk.integrations.apscheduler import APSchedulerIntegration

sentry_sdk.init(
dsn="___PUBLIC_DSN___",
integrations=[
APSchedulerIntegration(monitor_jobs=True),
],
)
```

Each job gets a monitor, created the first time the job runs. The monitor slug is the job's `id`. Give your jobs an explicit `id`. If a job has no `id`, the SDK uses its name, which defaults to the function name, and logs a warning.

The schedule comes from the job's trigger:

- `CronTrigger`: a crontab schedule in the trigger's timezone. Triggers that use seconds, years, weeks, or both `day` and `day_of_week` aren't monitored, and neither are triggers whose timezone has no IANA name (such as a fixed UTC offset).
- `IntervalTrigger`: an interval schedule. Intervals must be whole minutes.
- `DateTrigger`: one-off jobs aren't monitored.

Runs that APScheduler skips because the job reached `max_instances` don't send check-ins.

## Verify

```python
from apscheduler.schedulers.blocking import BlockingScheduler

def send_report():
1 / 0

scheduler = BlockingScheduler()
scheduler.add_job(send_report, "cron", minute="*", id="send-report")
scheduler.start()
```

Within a minute, a `send-report` cron monitor appears in Sentry with a failed check-in.

## Options

- `monitor_jobs`: Send check-ins for scheduled jobs. Defaults to `False`.
- `exclude_jobs`: A list of monitor slugs or regular expressions for jobs that shouldn't be monitored. Each entry must match the end of the slug, so `cleanup` also excludes `nightly-cleanup`. Use `^cleanup` to match only `cleanup`.

```python
APSchedulerIntegration(
monitor_jobs=True,
exclude_jobs=["cleanup", "report-.*"],
)
```

## Supported Versions

- APScheduler: 3.3+ (APScheduler 4 isn't supported)
- Python: 3.6+

<Include name="python-use-older-sdk-for-legacy-support.mdx" />
1 change: 1 addition & 0 deletions docs/platforms/python/integrations/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ The Sentry SDK uses integrations to hook into the functionality of popular libra
| <LinkWithPlatformIcon platform="python.airflow" label="Apache Airflow" url="/platforms/python/integrations/airflow/" /> | |
| <LinkWithPlatformIcon platform="python.beam" label="Apache Beam" url="/platforms/python/integrations/beam/" /> | |
| <LinkWithPlatformIcon platform="python.spark" label="Apache Spark" url="/platforms/python/integrations/spark/" /> | |
| <LinkWithPlatformIcon platform="python" label="APScheduler" url="/platforms/python/integrations/apscheduler/" /> | |
| <LinkWithPlatformIcon platform="python.arq" label="ARQ" url="/platforms/python/integrations/arq/" /> | ✓ |
| <LinkWithPlatformIcon platform="python.celery" label="Celery" url="/platforms/python/integrations/celery/" /> | ✓ |
| <LinkWithPlatformIcon platform="python.dramatiq" label="Dramatiq" url="/platforms/python/integrations/dramatiq/" /> | |
Expand Down
2 changes: 2 additions & 0 deletions platform-includes/crons/setup/python.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

If you're using **Celery Beat** to run your periodic tasks, have a look at our [Celery Beat Auto Discovery documentation](/platforms/python/integrations/celery/crons/).

If you're using **APScheduler**, see the [APScheduler integration](/platforms/python/integrations/apscheduler/).

## Job Monitoring

Use the Python SDK to monitor and notify you if your periodic task is missed (or doesn't start when expected), if it fails due to a problem in the runtime (such as an error), or if it fails by exceeding its maximum runtime.
Expand Down
Loading