Skip to content

Commit 0058822

Browse files
malcolmrebughinixrmx
authored andcommitted
detach only if the ctx token is not None
1 parent 8582da5 commit 0058822

File tree

1 file changed

+4
-1
lines changed
  • instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery

1 file changed

+4
-1
lines changed

instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,10 @@ def _trace_postrun(self, *args, **kwargs):
213213
self.update_task_duration_time(task_id)
214214
labels = {"task": task.name, "worker": task.request.hostname}
215215
self._record_histograms(task_id, labels)
216-
context_api.detach(token)
216+
# if the process sending the task is not instrumented
217+
# there's no incoming context and no token to detach
218+
if token is not None:
219+
context_api.detach(token)
217220

218221
def _trace_before_publish(self, *args, **kwargs):
219222
task = utils.retrieve_task_from_sender(kwargs)

0 commit comments

Comments
 (0)