Skip to content

Commit

Permalink
Fix bug in retrieve_task_id that fails to check the body for the task…
Browse files Browse the repository at this point in the history
… id when headers has data (but no task id), which wrongly kept spans open.
  • Loading branch information
wantsui committed Sep 27, 2024
1 parent 0bd5ea0 commit 1d5189a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ddtrace/contrib/internal/celery/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,12 @@ def retrieve_task_id(context):
"""
headers = context.get("headers")
body = context.get("body")
if headers:
# Check if the id is in the headers, then check the body for it.
# If we don't check the id first, we could wrongly assume no task_id
# when the task_id is in the body.
if headers and 'id' in headers:
# Protocol Version 2 (default from Celery 4.0)
return headers.get("id")
else:
elif body and 'id' in body:
# Protocol Version 1
return body.get("id")
4 changes: 4 additions & 0 deletions releasenotes/notes/fix-protocol-check-62ad7d096b1f36a9.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
tracing(celery): Fixes an issue where ``celery.apply`` spans using protocol 1 didn't close by improving the check for the task id in the body.

0 comments on commit 1d5189a

Please sign in to comment.