Skip to content

Commit

Permalink
fix(opentelemetry-instrumentation-celery): detach only if the ctx tok…
Browse files Browse the repository at this point in the history
…en is not None
  • Loading branch information
malcolmrebughini committed Sep 5, 2024
1 parent 9cced97 commit 78c883b
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ def _trace_postrun(self, *args, **kwargs):
self._record_histograms(task_id, labels)
context_api.detach(token)

# if the process sending the task is not instrumented
# there's no incoming context and no token to detach
if token is not None:
context_api.detach(token)

def _trace_before_publish(self, *args, **kwargs):
task = utils.retrieve_task_from_sender(kwargs)
task_id = utils.retrieve_task_id_from_message(kwargs)
Expand Down

0 comments on commit 78c883b

Please sign in to comment.