-
Notifications
You must be signed in to change notification settings - Fork 426
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
DD_TRACE_METHODS
does not fully wrap async functions
#10754
Comments
I think we have the same issue, my K8S python CI/CD runner is giving this traceback(obfuscated). We are using async code with pytests:
UPD: Please ignore this: Our variables:
ddtrace==2.14.2 |
DD_CIVISIBILITY_AGENTLESS_ENABLED can reduce traceback. However, it is still not perfect.. |
Do we have any plans to make it prettier than marking the issue as |
Hello! We apologize for the delayed response. The issue should be fixed with this PR. Thank you for your patience. |
Resolves issue #10754 Updated` trace_wrapper` to check if the target function is async (using `inspect.iscoroutinefunction`). If it is, the wrapper uses async/await to keep the tracing span open until the coroutine truly finishes instead of closing immediately when the coroutine is created. ## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) --------- Co-authored-by: Munir Abdinur <[email protected]>
Summary of problem
When using
DD_TRACE_METHODS
with async functions, only the coroutine creation gets wrapped in a span but not theawait
call. This results in a very short span for the coroutine and also doesn't allow child spans to nest correctly in the resulting flame graph.Which version of dd-trace-py are you using?
2.12.2
Which version of pip are you using?
23.3.2
Which libraries and their versions are you using?
`pip freeze`
build==1.2.1 bytecode==0.15.1 CacheControl==0.14.0 certifi==2024.2.2 cffi==1.16.0 charset-normalizer==3.3.2 cleo==2.1.0 crashtest==0.4.1 cryptography==42.0.7 ddtrace==2.12.2 Deprecated==1.2.14 distlib==0.3.8 dulwich==0.21.7 envier==0.5.2 exceptiongroup==1.2.2 fastjsonschema==2.19.1 filelock==3.14.0 idna==3.7 importlib_metadata==8.4.0 iniconfig==2.0.0 installer==0.7.0 jaraco.classes==3.4.0 jeepney==0.8.0 keyring==24.3.1 more-itertools==10.2.0 msgpack==1.0.8 opentelemetry-api==1.27.0 packaging==24.1 pexpect==4.9.0 pkginfo==1.10.0 platformdirs==4.2.2 pluggy==1.5.0 poetry==1.8.1 poetry-core==1.9.0 poetry-plugin-export==1.8.0 protobuf==5.28.2 ptyprocess==0.7.0 pycparser==2.22 pyproject_hooks==1.1.0 pytest==8.3.3 rapidfuzz==3.9.1 requests==2.32.1 requests-toolbelt==1.0.0 SecretStorage==3.3.3 shellingham==1.5.4 tomli==2.0.1 tomlkit==0.12.5 trove-classifiers==2024.5.17 typing_extensions==4.12.2 urllib3==2.2.1 virtualenv==20.26.2 wrapt==1.16.0 xmltodict==0.13.0 zipp==3.20.2How can we reproduce your problem?
Put this code in
src/foo.py
and useddtrace-run
withDD_TRACE_METHODS=src.foo:bar
, then call bothbar()
andbaz()
.More details on docker compose setup
docker-compose.yml:
Dockerfile:
src/main.py:
What is the result that you get?
The output shows that a span is created but finishes before
bar() start
is logged.Using
docker compose log app | grep -E 'INFO|DEBUG:ddtrace._trace.tracer'
to extract relevant lines:This behavior is also observed even if
bar
is not awaited.What is the result that you expected?
On the other hand, the span for
baz
finishes only after it completes, which is what I'd expect.The text was updated successfully, but these errors were encountered: