fix(profiling): link span to worker thread profile#18089
fix(profiling): link span to worker thread profile#18089gh-worker-dd-mergequeue-cf854d[bot] merged 10 commits into
Conversation
Codeowners resolved as |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bb0b8c0171
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
bb0b8c0 to
dda374c
Compare
BenchmarksBenchmark execution time: 2026-05-19 15:13:33 Comparing candidate commit 00827a8 in PR branch Found 0 performance improvements and 2 performance regressions! Performance is the same for 364 metrics, 9 unstable metrics. scenario:span-start
scenario:telemetryaddmetric-1-count-metric-1-times
|
wantsui
left a comment
There was a problem hiding this comment.
LGTM from an idm perspective. Do you need release notes for this fix?
KowalskiThomas
left a comment
There was a problem hiding this comment.
This is very cool. I'm really not an expert on the span <-> profile linking stuff, but I really like this for context propagation 🤩
dda374c to
0c5bdc9
Compare
anthonypalmeira
left a comment
There was a problem hiding this comment.
Thanks for taking care of this
f31e255 to
382da82
Compare
11b13c1 to
8a4c02c
Compare
|
cf2a19b to
00827a8
Compare
mabdinur
left a comment
There was a problem hiding this comment.
Left some questions and nits. Overall looks good
b78f118 to
e236612
Compare
e236612 to
85841d7
Compare
47f7fc4 to
3508889
Compare

PROF-12202
Summary
Fixes profiler span linkage for
ThreadPoolExecutor(and other concurrent.futures) worker threads so CPU samples appear in span-to-profile flame graphs with the correct span id, local root span id, and trace type.The stack profiler maintains
ThreadSpanLinksthorugh stack.link_span(). Previously it only handled Span activations.The futures integration propagates traces across threads with a Context (tracer._activate_context), not a Span.
link_spanwas a no-op for Context, so worker threads were never registered. Their samples had no span id label and did not show up in span-to-profile views.link_spanhandles ContextWhen a Context with span_id is activated, call the native linker with
context.span_id(parent at submit time)_meta, orspan_idif absent_metawhen presentProfiler linkage using
Context._meta(futures path)Profiler fields are set using internal meta keys _dd.profiling.local_root_span_id and _dd.profiling.span_type
On
executor.submit, when an active span exists:attach_profiler_link()writes meta on a copied_metadict; this make sure parent context is unchanged. Values come fromcurrent_span._local_rootso nested spans still get the true trace root.read_profiler_link()is used inlink_span(Context)on the worker.Child spans in workers
Spans created in a worker with
tracer.trace()have_parentis None butparent_idset. Their local root would incorrectly be the child itself. On Context activation we store local root + span type in thread-local andlink_span()uses that for context-propagated children.Testing
Risks
Additional Notes