|
1 | 1 | """ |
2 | 2 | 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:: |
4 | 7 |
|
5 | 8 | import celery |
6 | 9 | from ddtrace import patch |
|
12 | 15 | def my_task(): |
13 | 16 | pass |
14 | 17 |
|
15 | | -
|
16 | 18 | class MyTask(app.Task): |
17 | 19 | def run(self): |
18 | 20 | pass |
19 | 21 |
|
20 | 22 |
|
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:: |
23 | 25 |
|
24 | | - import celery |
25 | | - from ddtrace.contrib.celery import patch_app, patch_task |
| 26 | + from ddtrace import Pin |
26 | 27 |
|
27 | | - # patch only this application |
28 | 28 | app = celery.Celery() |
29 | | - app = patch_app(app) |
30 | 29 |
|
31 | | - # or if you didn't patch the whole application, just patch |
32 | | - # a single function or class based Task |
33 | 30 | @app.task |
34 | | - def fn_task(): |
| 31 | + def compute_stats(): |
35 | 32 | pass |
36 | 33 |
|
| 34 | + # globally |
| 35 | + Pin.override(app, service='background-jobs') |
| 36 | +
|
| 37 | + # by task |
| 38 | + Pin.override(compute_stats, service='data-processing') |
37 | 39 |
|
38 | | - class BaseClassTask(celery.Task): |
39 | | - def run(self): |
40 | | - pass |
41 | 40 |
|
| 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 |
42 | 44 |
|
43 | | - BaseClassTask = patch_task(BaseClassTask) |
44 | | - fn_task = patch_task(fn_task) |
45 | 45 | """ |
46 | 46 | from ...utils.importlib import require_modules |
47 | 47 |
|
|
0 commit comments