-
Notifications
You must be signed in to change notification settings - Fork 411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(celery): close celery.apply
spans even without after_task_publish, when using apply_async
#10676
base: main
Are you sure you want to change the base?
Conversation
…signal does not get called
Datadog ReportBranch report: ✅ 0 Failed, 673 Passed, 523 Skipped, 22m 41.31s Total duration (14m 7.95s time saved) |
|
BenchmarksBenchmark execution time: 2024-09-27 14:33:35 Comparing candidate commit 5b96ae7 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 267 metrics, 51 unstable metrics. |
celery.apply
spans when using apply_async, even when after_task_publish isn't calledcelery.apply
spans even without after_task_publish, when using apply_async
celery.apply
spans even without after_task_publish, when using apply_asynccelery.apply
spans even without after_task_publish, when using apply_async
…he after task publish signal is not called, there are no spans at the moment so the test fails.
update with latest changes on the main branch
add changes from main branch
@@ -131,6 +131,6 @@ def retrieve_task_id(context): | |||
if headers: | |||
# Protocol Version 2 (default from Celery 4.0) | |||
return headers.get("id") | |||
else: | |||
elif body: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: usually good to have one PR per change you're making. This is a one-liner so arguable, but it makes it easier to rollback/make sure you're not missing something in the future
--- | ||
fixes: | ||
- | | ||
tracing(celery): Fixes an issue where `celery.apply` spans didn't close if the after_task_publish or task_postrun signals didn't get called. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: would add a little bit about why they weren't called (exception generated in handling)
releasenotes/notes/fix-celery-apply-async-span-close-b7a8db188459f5b5.yaml
Outdated
Show resolved
Hide resolved
…459f5b5.yaml Co-authored-by: Emmett Butler <[email protected]>
… id when headers has data (but no task id), which wrongly kept spans open.
…the task id when headers has data (but no task id), which wrongly kept spans open." This reverts commit b4556d2.
add latest main changes
Credits go to @tabgok for going through this with me in great detail!
The instrumentation for the Celery integration relies on various Celery signals in order to start and end the span when calling on
apply_async
.The integration can fail in two known places, which can lead to broken context propagation (and unexpected traces).
Issue 1: Closing signals don't get called.
before_task_publish
to start the span thenafter_task_publish
to close the span. If theafter_task_publish
signal never gets called (which can happen if a Celery exception occurs while processing the app), then the span won't finish.task_prerun
andtask_postrun
.Issue 2: Even if
after_task_publish
is called, the integration previously only closed the span if the task or task id was present. However, it is possible that there is a lingering span kept open but doesn't return atask_id
and instead justreturn
nothing. This is bad because that means the remnants of thatcelery.apply
span is never closed either.To address both, this PR patches
apply_async
so that there is a check to see if there is a span lingering around and closes it whenapply_task
is called.Meanwhile, the fix to
celery/utils.py
is to address the fact that some times, the returning response returns an emptybody
, in which case, we should not try to runbody.get('id')
and just returnNone
.Open Item
except
clause, but I'm not sure if I should.To track this, I added new logs in debug mode:
and
Checklist
Reviewer Checklist