Skip to content

Commit db746d1

Browse files
antonpirkergetsantry[bot]lizokm
authored
Document new fine grained controll over distributed tracing (#7757)
--------- Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com> Co-authored-by: Liza Mock <[email protected]>
1 parent 94ea850 commit db746d1

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

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

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,14 @@ You can pass the following keyword arguments to `CeleryIntegration()`:
9494

9595
- `propagate_traces`
9696

97-
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.
97+
Propagate Sentry tracing information to the Celery task. This makes it possible to link Celery task errors to the function that triggered the task.
9898

99-
The default is `True`.
99+
If this is set to `False`:
100+
101+
- errors in Celery tasks won't be matched to the triggering function.
102+
- your Celery tasks will start a new trace and won't be connected to the trace in the calling function.
103+
104+
The default is `True`.
100105

101106
- `monitor_beat_tasks`:
102107

@@ -115,3 +120,39 @@ You can pass the following keyword arguments to `CeleryIntegration()`:
115120
See <PlatformLink to="/crons/#celery-beat-auto-discovery">Celery Beat Auto Discovery</PlatformLink> to learn more.
116121

117122
The default is `None`.
123+
124+
## Distributed Traces
125+
126+
Distributed tracing extends the trace from the code that's running your Celery task so that it includes the code that initiated the task.
127+
128+
You can disable this globally with the `propagate_traces` parameter, documented above. If you set `propagate_traces` to `False`, all Celery tasks will start their own trace.
129+
130+
If you want to have more fine-grained control over trace distribution, you can override the `propagate_traces` option by passing the `sentry-propagate-traces` header when starting the Celery task:
131+
132+
```python
133+
import sentry_sdk
134+
135+
# Enable global distributed traces (this is the default, just to be explicit.)
136+
sentry_sdk.init(
137+
dsn="___PUBLIC_DSN___",
138+
integrations=[
139+
CeleryIntegration(propagate_traces=True),
140+
],
141+
)
142+
143+
# This will propagate the trace:
144+
my_task_a.delay("some parameter")
145+
146+
# This will propagate the trace:
147+
my_task_b.apply_async(
148+
args=("some_parameter", )
149+
)
150+
151+
# This will NOT propagate the trace. (The task will start its own trace):
152+
my_task_b.apply_async(
153+
args=("some_parameter", ),
154+
headers={"sentry-propagate-traces": False},
155+
)
156+
157+
# Note: overriding the tracing behaviour using `task_x.delay()` is not possible.
158+
```

0 commit comments

Comments
 (0)