Skip to content

Commit a553ed6

Browse files
author
Emanuele Palazzetti
authored
[celery] update Celery documentation based on the new instrumentation (#531)
* [celery] update Celery documentation based on the new instrumentation * [celery] updated service names description to use Celery vocabulary * [celery] be more specific on what calls are instrumented via Celery signal framework
1 parent 0ea3774 commit a553ed6

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

ddtrace/contrib/celery/__init__.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
"""
22
The Celery integration will trace all tasks that are executed in the
3-
background. To trace your Celery application, call the patch method::
3+
background. Functions and class based tasks are traced only if the Celery API
4+
is used, so calling the function directly or via the ``run()`` method will not
5+
generate traces. On the other hand, calling ``apply()`` and ``apply_async()``
6+
will produce tracing data. To trace your Celery application, call the patch method::
47
58
import celery
69
from ddtrace import patch
@@ -12,36 +15,33 @@
1215
def my_task():
1316
pass
1417
15-
1618
class MyTask(app.Task):
1719
def run(self):
1820
pass
1921
2022
21-
If you don't need to patch all Celery tasks, you can patch individual
22-
applications or tasks using a fine grain patching method::
23+
To change Celery service name, you can update the attached ``Pin``
24+
instance::
2325
24-
import celery
25-
from ddtrace.contrib.celery import patch_app, patch_task
26+
from ddtrace import Pin
2627
27-
# patch only this application
2828
app = celery.Celery()
29-
app = patch_app(app)
3029
31-
# or if you didn't patch the whole application, just patch
32-
# a single function or class based Task
3330
@app.task
34-
def fn_task():
31+
def compute_stats():
3532
pass
3633
34+
# globally
35+
Pin.override(app, service='background-jobs')
36+
37+
# by task
38+
Pin.override(compute_stats, service='data-processing')
3739
38-
class BaseClassTask(celery.Task):
39-
def run(self):
40-
pass
4140
41+
By default, reported service names are:
42+
* ``celery-producer`` when tasks are enqueued for processing
43+
* ``celery-worker`` when tasks are processed by a Celery process
4244
43-
BaseClassTask = patch_task(BaseClassTask)
44-
fn_task = patch_task(fn_task)
4545
"""
4646
from ...utils.importlib import require_modules
4747

0 commit comments

Comments
 (0)