Repository navigation
test(profiling): add asyncio task span attribution tests - #21236
gh-worker-dd-mergequeue-cf854d[bot] merged 7 commits into
Conversation
Add end-to-end tests that run the stack profiler with the tracer and check the trace endpoint and span id labels on asyncio task samples. On main, span labels are tracked per thread, not per task, so a task can pick up another task's endpoint, an untraced task can borrow a traced task's span, and a task started with an empty Context still gets the creator's endpoint. Every test here fails on main and is marked xfail(strict=True), so the fix in #19736 has to remove the markers when it makes them pass.
Codeowners resolved asResolved from the full PR diff against |
Dependency direction analysis
|
🎉 All green!🧪 All tests passed 🔗 Commit SHA: a7f7798 | Docs | View more details | Give us feedback! |
- Check span id and local root span id for concurrent traced tasks. - Eager test: drop the single-value EMPTY_CONTEXT parameter, rename it, use asyncio.run, and check the eager first step and the resumed step on their own samples.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
KowalskiThomas
left a comment
There was a problem hiding this comment.
Testing only so to be honest I haven't really reviewed it!
|
There was a problem hiding this comment.
More details
The strict expected-failure markers match the known per-thread attribution bug. Static review found no actionable defect in the task synchronization, version guards, or label assertions.
🤖 Bits Code Review · Commit 9cd0f91
Turn on per-task attribution for asyncio tasks where the profiler installs its task key writers. A sample of an asyncio task now carries the span of that task's own key, or no span, instead of the span that any task on the thread activated last. Remove the strict xfails that #21236 added to the asyncio endpoint label tests. Add end-to-end tests that decode profiles for inherited, eager, finished, OpenTelemetry, uvloop and asyncio.Runner cases. The concurrent-task tests check that every sample of each task carries that task's span or no span, and they fail with per-task attribution off. Some checks only count a task's own samples. Echion, the native stack walker, can render one task's frames under another task in two cases that predate this change: a sample that overlaps the moment a task starts or stops waiting, and uvloop set up through uvloop.install() or a policy before Python 3.11, where it does not find the loop boundary.
## Description JIRA: [PROF-16348](https://datadoghq.atlassian.net/browse/PROF-16348) The stack profiler stores each thread's active span in `SpanLinks`, keyed by thread id. All asyncio tasks and gevent greenlets on one thread share that entry, so their samples all get the span that was activated last on the thread. The xfail tests in `tests/profiling/collector/test_stack_asyncio_endpoint_labels.py` (#21236) show this for asyncio. This PR keys `SpanLinks` by execution unit instead: a `(domain, identifier)` pair, where the domain is `Thread`, `AsyncioTask` or `Greenlet`. Follow-up PRs will write task and greenlet keys, so each one carries its own span. This PR only changes the existing methods and their callers: - `link_span`, `unlink_span` and `get_active_span` (renamed from `get_active_span_from_thread_id`, since it no longer takes a thread id) take a `SpanLinkKey`. - The callers in `stack.cpp` and `stack_renderer.cpp` pass `SpanLinkKey::thread(id)`. - Only thread keys are written, so behavior is unchanged. ## Testing - The existing `SpanLinks` C++ tests now pass thread keys. - New `KeysWithEqualIdentifiersInDifferentDomainsAreSeparate`: a thread key and a task key with the same id don't affect each other. - Ran locally on Linux aarch64: the native `stack_test` suite, and clang-tidy with CI's checks on the changed files. ## Risks None. Only thread keys are written, and each method does the same thing for them as before. ## Additional Notes No release note: an internal refactor with no user-visible change. [PROF-16348]: https://datadoghq.atlassian.net/browse/PROF-16348?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ Co-authored-by: taegyun.kim <taegyun.kim@datadoghq.com>
Description
JIRA: PROF-16348
The stack profiler tracks span labels per thread, not per asyncio task. Tasks on the same event loop share a thread, so a task's samples get the span and endpoint of whichever span was activated on the thread last, even if it belongs to another task.
These tests cover:
mainkeeps_asyncio_task_endpoints_separatedoes_not_use_thread_endpoint_for_untraced_asyncio_taskrespects_explicit_empty_child_task_contextContextgets its creator's endpoint.omits_unverifiable_pre312_custom_factory_contextrespects_explicit_empty_context_for_eager_taskThey're all
xfail(strict=True). #19736 fixes this and removes the markers, so its diff shows which cases it fixes.Testing
Ran the file on 3.9 to 3.14. Every test xfails or is skipped for its version. To make sure they fail because of the bug and not something else, I also checked that:
--runxfail, each test fails at its first label assertion, andRisks
None, test-only. Like other wall-time tests these are timing-sensitive, and a strict xfail that passes by chance fails the test.
Additional Notes