Skip to content

Commit e067121

Browse files
author
Emanuele Palazzetti
committed
[celery] use attach/detach verbs instead of propagate/remove
1 parent 6468d8b commit e067121

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

ddtrace/contrib/celery/signals.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
from .util import (
99
tags_from_context,
1010
retrieve_task_id,
11-
propagate_span,
11+
attach_span,
12+
detach_span,
1213
retrieve_span,
13-
remove_span,
1414
)
1515

1616

@@ -33,7 +33,7 @@ def trace_prerun(*args, **kwargs):
3333

3434
# propagate the `Span` in the current task Context
3535
span = pin.tracer.trace(c.WORKER_ROOT_SPAN, service=c.WORKER_SERVICE, resource=task.name)
36-
propagate_span(task, task_id, span)
36+
attach_span(task, task_id, span)
3737

3838

3939
def trace_postrun(*args, **kwargs):
@@ -55,7 +55,7 @@ def trace_postrun(*args, **kwargs):
5555
span.set_tags(tags_from_context(kwargs))
5656
span.set_tags(tags_from_context(task.request))
5757
span.finish()
58-
remove_span(task, task_id)
58+
detach_span(task, task_id)
5959

6060

6161
def trace_before_publish(*args, **kwargs):
@@ -86,7 +86,7 @@ def trace_before_publish(*args, **kwargs):
8686
# Note: adding tags from `traceback` or `state` calls will make an
8787
# API call to the backend for the properties so we should rely
8888
# only on the given `Context`
89-
propagate_span(task, task_id, span)
89+
attach_span(task, task_id, span)
9090

9191

9292
def trace_after_publish(*args, **kwargs):
@@ -105,7 +105,7 @@ def trace_after_publish(*args, **kwargs):
105105
return
106106
else:
107107
span.finish()
108-
remove_span(task, task_id)
108+
detach_span(task, task_id)
109109

110110

111111
def trace_failure(*args, **kwargs):

ddtrace/contrib/celery/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def tags_from_context(context):
5050
return tags
5151

5252

53-
def propagate_span(task, task_id, span):
53+
def attach_span(task, task_id, span):
5454
"""Helper to propagate a `Span` for the given `Task` instance. This
5555
function uses a `WeakValueDictionary` that stores a Datadog Span using
5656
the `task_id` as a key. This is useful when information must be
@@ -64,7 +64,7 @@ def propagate_span(task, task_id, span):
6464
weak_dict[task_id] = span
6565

6666

67-
def remove_span(task, task_id):
67+
def detach_span(task, task_id):
6868
"""Helper to remove a `Span` in a Celery task when it's propagated.
6969
This function handles tasks where the `Span` is not attached.
7070
"""

tests/contrib/celery/test_utils.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
from ddtrace.contrib.celery.util import (
66
tags_from_context,
77
retrieve_task_id,
8-
propagate_span,
8+
attach_span,
9+
detach_span,
910
retrieve_span,
10-
remove_span,
1111
)
1212

1313
from .base import CeleryBaseTestCase
@@ -72,7 +72,7 @@ def fn_task():
7272
# propagate and retrieve a Span
7373
task_id = '7c6731af-9533-40c3-83a9-25b58f0d837f'
7474
span_before = self.tracer.trace('celery.run')
75-
propagate_span(fn_task, task_id, span_before)
75+
attach_span(fn_task, task_id, span_before)
7676
span_after = retrieve_span(fn_task, task_id)
7777
ok_(span_before is span_after)
7878

@@ -85,10 +85,10 @@ def fn_task():
8585
# propagate a Span
8686
task_id = '7c6731af-9533-40c3-83a9-25b58f0d837f'
8787
span = self.tracer.trace('celery.run')
88-
propagate_span(fn_task, task_id, span)
88+
attach_span(fn_task, task_id, span)
8989
# delete the Span
9090
weak_dict = getattr(fn_task, '__dd_task_span')
91-
remove_span(fn_task, task_id)
91+
detach_span(fn_task, task_id)
9292
ok_(weak_dict.get(task_id) is None)
9393

9494
def test_span_delete_empty(self):
@@ -102,7 +102,7 @@ def fn_task():
102102
exception = None
103103
task_id = '7c6731af-9533-40c3-83a9-25b58f0d837f'
104104
try:
105-
remove_span(fn_task, task_id)
105+
detach_span(fn_task, task_id)
106106
except Exception as e:
107107
exception = e
108108
ok_(exception is None)
@@ -117,7 +117,7 @@ def fn_task():
117117

118118
# propagate and finish a Span for `fn_task`
119119
task_id = '7c6731af-9533-40c3-83a9-25b58f0d837f'
120-
propagate_span(fn_task, task_id, self.tracer.trace('celery.run'))
120+
attach_span(fn_task, task_id, self.tracer.trace('celery.run'))
121121
weak_dict = getattr(fn_task, '__dd_task_span')
122122
ok_(weak_dict.get(task_id))
123123
# flush data and force the GC

0 commit comments

Comments
 (0)