DataDog / dd-trace-py

Datadog Python APM Client
https://ddtrace.readthedocs.io/
Other
552 stars 416 forks source link

fix(celery): account for a chains scenario #11498

Open wantsui opened 22 hours ago

wantsui commented 22 hours ago

We've made a few changes to handle celery context recently:

In particular the goal of https://github.com/DataDog/dd-trace-py/pull/10676 was to handle a scenario where a long running task may run into an exception, preventing it from closing.

Unfortunately, this scenario did not account for cases where tasks are chained and may not close until later.

See: https://github.com/DataDog/dd-trace-py/issues/11479

With this PR, the sample app in https://github.com/DataDog/dd-trace-py/issues/11479 would attach the celery specific span back to the root span.

This is a draft PR for now because I am waiting to see if there are unexpected failures if we remove the logic to close unclosed prerun spans in some cases. (Some more testing on this is needed).

I also need to add tests for the chains scenario.

Checklist

Reviewer Checklist

github-actions[bot] commented 22 hours ago

CODEOWNERS have been resolved as:

ddtrace/contrib/internal/celery/app.py                                  @DataDog/apm-core-python @DataDog/apm-idm-python
ddtrace/contrib/internal/celery/signals.py                              @DataDog/apm-core-python @DataDog/apm-idm-python