Repository navigation
fix(profiling): correlate AnyIO worker profiles - #19737
taegyunkim wants to merge 2 commits into
Conversation
5ecd359 to
6e6d489
Compare
6b510d0 to
fed4ca0
Compare
❌ ErrorsYour PR has failed checks. Please review the issues below and take necessary action before merging. 🚦 1 Pipeline job failed
ℹ️ InfoNo other issues found (see more)🧪 All tests passed Useful? React with 👍 / 👎 This comment will be updated automatically if new data arrives.🔗 Commit SHA: dbd926e | Docs | View more details | Give us feedback! |
BenchmarksBenchmark execution time: 2026-09-27 11:15:55 Comparing candidate commit dbd926e in PR branch Found 0 performance improvements and 10 performance regressions! Performance is the same for 612 metrics, 10 unstable metrics, 7 known flaky benchmarks, 17 flaky benchmarks without significant changes.
|
1ef4500 to
38cc0d2
Compare
fed4ca0 to
9c149ad
Compare
Codeowners resolved asResolved from the full PR diff against |
Circular import analysis
|
Dependency direction analysis
|
9c149ad to
ab8acda
Compare
52802b4 to
c4281a1
Compare
d3a462e to
415103d
Compare
c4281a1 to
08c344b
Compare
01cc2a8 to
0b57e33
Compare
df6bb62 to
926aef9
Compare
653909d to
8f8861f
Compare
04afddd to
722b0a4
Compare
722b0a4 to
2126ad0
Compare
…rofiling-anyio-span-links # Conflicts: # riotfile.py
3a38758 to
dbd926e
Compare
7d55ec9 to
c1a0208
Compare
|
Closing along with #19736, which this was stacked on. The work is being redone in smaller PRs. |
Description
JIRA: PROF-16348
Stack restack
This branch has been merged with the latest #19736 head at
c1a0208ae2and pushed atdbd926e119. The merge carries the latestorigin/mainchanges while preserving the AnyIO worker-attribution behavior and its inherited finish/reset race protection.Stacked on #19736.
AnyIO copies the active tracing context when
anyio.to_thread.run_syncoffloads synchronous work, but entering that copied context does not emit a tracing activation event. The profiler therefore associates the request span with the asyncio task while worker-thread samples remain unattributed.This PR wraps the callable submitted through AnyIO's public thread-offload API. On worker entry, it publishes inherited profiler span metadata to the physical thread after validating the lifecycle generation and source-span lifetime. It clears the physical mapping unconditionally when the callable exits so pooled workers cannot retain attribution across requests.
This reuses the lifecycle coordinator from #19736 and the existing native physical-thread mapping. It does not change tracing semantics or add native code.
Testing
Latest main merge validation
The stack merge commit is SSH-signed.
profile-anyioenvironment viascripts/run-tests: 1 passed.scripts/lint fmtpassed for the affected profiler and regression-test files.scripts/lint suitespec-checkpassed.Asyncio naming follow-up validation
Focused asyncio, endpoint-attribution, and span-link lifecycle tests via
scripts/run-tests:--ddtraceon Python 3.13.13.scripts/lint checks: passed.These are local validation results. New remote CI results are pending after the stack push.
Native CI follow-up validation
The allocation-failure test was rebuilt and run through CTest on Linux with Clang 19.1.7 in three configurations: ASan/LSan/UBSan, Valgrind 3.24.0, and ordinary RelWithDebInfo. All three passed on both #19736 and the restacked gevent tip. Valgrind reported zero errors and no leaks.
scripts/lint checkspassed on both branches. This validates the failing test locally, not the entire new remote CI pipeline; CI is rerunning after the push.Restacked validation
On Python 3.12.13, with a freshly rebuilt native extension:
scripts/run-tests: 88 passed, 4 skipped.build_standalone.sh -- RelWithDebInfo stack_test: 32 stack tests and 23 wrapper tests passed.scripts/lint checks: passed.scripts/run-benchmarks --listfound no matching suites, so no benchmark results are claimed.The existing testing and staging results below predate this follow-up.
scripts/lint checkson the complete rewritten stackscripts/run-tests --venv bbf818a -- tests/profiling/collector/test_anyio_span_links.pyprofile-anyioenvironment: 1 passedThe focused regression covers endpoint and span attribution, then verifies cleanup when the same AnyIO worker is reused outside the trace.
A dedicated Python 3.12 environment installs AnyIO only for this regression. This replaces the previous broad dependency change, reducing generated profiling requirement changes from 38 files to one.
Rapid Python smoke test
The cumulative asyncio and AnyIO stack was previously deployed to
rapid_python_http_smoke_testasrapid-td-anyio-span-links.9c149ad273dc90a40860d96f3351383f12cfae73_run_with_anyio_span, with no error-level application logs after the deployment became ready.Risks
The wrapper runs only for AnyIO thread offloads while stack profiling is enabled. Cleanup is unconditional in a
finallyblock. Weak source-span validation prevents copied contexts from republishing finished or collected spans. Failures are contained to missing profile attribution and do not alter AnyIO or tracing behavior.Additional Notes
Review this stack in order:
Customer-facing release note:
releasenotes/notes/fix-anyio-worker-profile-attribution-abbf595ce67e6ad1.yaml.