Skip to content

Commit a8362ba

Browse files
Docs for exclude_beat_tasks (#6995)
* Docs for `exclude_beat_tasks` --------- Co-authored-by: Shana Matthews <shana.l.matthews@gmail.com>
1 parent 8f49120 commit a8362ba

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

src/platform-includes/crons/setup/python.celery.mdx

+26
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,32 @@ You don't need to create Cron Monitors for your tasks on Sentry.io, we'll do it
5151

5252
</Note>
5353

54+
### Excluding Celery Beat Tasks from Auto Discovery
55+
56+
You can exclude Celery Beat tasks from being auto-instrumented. To do this, add a list of tasks you want to exclude as option `exclude_beat_tasks` when creating `CeleryIntegration`. The list can contain simple strings with the full task name, as specified in the Celery Beat schedule, or regular expressions to match multiple tasks.
57+
58+
```python
59+
exclude_beat_tasks = [
60+
"some-task-a",
61+
"payment-check-.*",
62+
]
63+
64+
sentry_sdk.init(
65+
dsn='___PUBLIC_DSN___',
66+
integrations=[
67+
CeleryIntegration(
68+
monitor_beat_tasks=True,
69+
exclude_beat_tasks=exclude_beat_tasks),
70+
],
71+
environment="local.dev.grace",
72+
release="v1.0",
73+
)
74+
```
75+
76+
In this example the task `some-task-a` and all tasks with a name starting with `payment-check-` will be ignored.
77+
78+
For more information, see the documentation for <PlatformLink to="/#options">options on CeleryIntegration</PlatformLink>.
79+
5480
## Manual Task Monitoring
5581

5682
We provide a lightweight decorator to make monitoring individual tasks easier. To use it, add `@sentry_sdk.monitor` to your Celery task (or any function), then supply a `monitor_slug` of a monitor created previously on Sentry.io. Once this is done, every time the task (or function) is executed, telemetry data will be captured when a task is started, when it finishes, and when it fails.

src/platforms/python/guides/celery/index.mdx

+46
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,49 @@ Sentry uses custom message headers for distributed tracing. For Celery versions
6767
The fix for the custom headers propagation issue was introduced to Celery project ([PR](https://github.com/celery/celery/pull/6374)) starting with version 5.0.1. However, the fix was not backported to versions 4.x.
6868

6969
</Alert>
70+
71+
## Options
72+
73+
To set options on `CeleryIntegration` to change its behavior, add it explicitly to your `sentry_sdk.init()`:
74+
75+
```python
76+
import sentry_sdk
77+
from sentry_sdk.integrations.celery import CeleryIntegration
78+
79+
sentry_sdk.init(
80+
dsn="___PUBLIC_DSN___",
81+
# ...
82+
integrations=[
83+
CeleryIntegration(
84+
monitor_beat_tasks=True,
85+
exclude_beat_tasks=["unimportant-task", "payment-check-.*"],
86+
),
87+
],
88+
)
89+
```
90+
91+
You can pass the following keyword arguments to `CeleryIntegration()`:
92+
93+
- `propagate_traces`
94+
95+
Propagate Sentry tracing information to the Celery task. This makes it possible to link errors in Celery tasks to the function that triggered the Celery task. If this is set to `False`, errors in Celery tasks can't be matched to the triggering function.
96+
97+
The default is `True`.
98+
99+
- `monitor_beat_tasks`:
100+
101+
Turn auto-instrumentation on or off for Celery Beat tasks using Sentry Crons.
102+
103+
See <PlatformLink to="/crons/#celery-beat-auto-discovery">Celery Beat Auto Discovery</PlatformLink> to learn more.
104+
105+
The default is `False`.
106+
107+
- `exclude_beat_tasks`:
108+
109+
A list of Celery Beat tasks that should be excluded from auto-instrumentation using Sentry Crons. Only applied if `monitor_beat_tasks` is set to `True`.
110+
111+
The list can contain strings with the names of tasks in the Celery Beat schedule to be excluded. It can also include regular expressions to match multiple tasks. For example, if you include `"payment-check-.*"` every task starting with `payment-check-` will be excluded from auto-instrumentation.
112+
113+
See <PlatformLink to="/crons/#celery-beat-auto-discovery">Celery Beat Auto Discovery</PlatformLink> to learn more.
114+
115+
The default is `None`.

0 commit comments

Comments
 (0)