Skip to content

refactor(profiling): key native span links by execution unit - #21621

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
mainfrom
taegyunkim/profiling-span-link-key
Nov 10, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
mainfrom
taegyunkim/profiling-span-link-key

Conversation

@taegyunkim

@taegyunkim taegyunkim commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Description

JIRA: 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.

SpanLinks maps a thread id to its active span. Change the key to a (domain, identifier) pair with Thread, AsyncioTask and Greenlet domains, so that later changes can give each asyncio task and greenlet its own span next to the thread's. Only thread keys are written for now: existing methods and callers change only to build a thread key, and behavior is unchanged.
@taegyunkim taegyunkim added the changelog/no-changelog A changelog entry is not required for this PR. label Nov 9, 2026
@taegyunkim taegyunkim added the Profiling Continous Profling label Nov 9, 2026
@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Dependency direction analysis

⚠️ Existing dependency direction violations

There are 77 dependency direction violations that already exist on the base branch and have not been changed by this PR.

Show existing violations (showing 5 of 77 highest severity)
ddtrace.internal.tracemethods -×-> ddtrace.trace  (internal-core -> product:tracing, score=120)
ddtrace.llmobs._integrations.crewai -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=118)
ddtrace.llmobs._integrations.langchain -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=118)
ddtrace.llmobs._integrations.base -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=118)
ddtrace.llmobs._integrations.bedrock_agents -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=118)

To see all violations, download the layers-base.json and layers-pr.json artifacts from this CI job and run:

uv run --script scripts/import-analysis/layers.py compare layers-base.json layers-pr.json

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Codeowners resolved as

Resolved from the full PR diff against main using the target branch CODEOWNERS file.
CODEOWNERS team requests not listed below are not required by the current file set.

ddtrace/internal/datadog/profiling/stack/include/span_links.hpp         @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/src/span_links.cpp             @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/src/stack.cpp                  @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/src/stack_renderer.cpp         @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/test/test_span_links.cpp       @DataDog/profiling-python

@taegyunkim
taegyunkim marked this pull request as ready for review November 9, 2026 21:31
@taegyunkim
taegyunkim requested a review from a team as a code owner November 9, 2026 21:31
@taegyunkim
taegyunkim requested a review from gyuheon0h November 9, 2026 21:31
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T21:33:18.195835Z cecff1c Draft marked ready
🔒 Security Review ✅ Completed 2026-11-09T21:33:59.490429Z cecff1c Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cecff1c269

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@datadog-prod-us1-6 datadog-prod-us1-6 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: PASS

More details

Existing span-link writers and renderers consistently use matching thread-domain keys, preserving lookup and cleanup behavior. Task and greenlet attribution remains deferred to follow-up changes.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit cecff1c

@pr-commenter

pr-commenter Bot commented Nov 9, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-11-09 21:47:38

Comparing candidate commit cecff1c in PR branch taegyunkim/profiling-span-link-key with baseline commit c78138a in branch main.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 586 metrics, 9 unstable metrics, 1 flaky benchmarks without significant changes.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

Unstable benchmarks

These benchmarks have a confidence interval too wide to call a change; treat them as noise rather than signal.

scenario:coreapiscenario-context_with_data_listeners

  • unstable execution_time [-727.703ns; +693.158ns] or [-6.789%; +6.467%]

scenario:coreapiscenario-core_dispatch_50_listeners

  • unstable execution_time [-1781.552ns; +1919.116ns] or [-8.882%; +9.568%]

scenario:coreapiscenario-core_dispatch_exception_listeners

  • unstable execution_time [-1722.796ns; +1826.928ns] or [-8.914%; +9.453%]

scenario:coreapiscenario-core_dispatch_listeners

  • unstable execution_time [-400.254ns; +331.217ns] or [-9.173%; +7.591%]

scenario:coreapiscenario-core_dispatch_no_args_listeners

  • unstable execution_time [-207.429ns; +228.994ns] or [-7.646%; +8.441%]

scenario:coreapiscenario-core_dispatch_with_results_1_listener

  • unstable execution_time [-98.547ns; +78.503ns] or [-6.642%; +5.291%]

scenario:coreapiscenario-core_dispatch_with_results_50_listeners

  • unstable execution_time [-4500.745ns; +5005.107ns] or [-8.861%; +9.854%]

scenario:coreapiscenario-core_dispatch_with_results_listeners

  • unstable execution_time [-1114.340ns; +850.453ns] or [-10.279%; +7.845%]

scenario:packagesupdateimporteddependencies-import_many_stdlib_cached

  • unstable execution_time [-55923.773ns; +55295.916ns] or [-9.651%; +9.543%]

Known flaky benchmarks

These benchmarks are marked as flaky and will not trigger a failure. Modify FLAKY_BENCHMARKS_REGEX to control which benchmarks are marked as flaky.

Known flaky benchmarks without significant changes:

  • scenario:packagespackageforrootmodulemapping-cache_off

@KowalskiThomas KowalskiThomas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me; I assume more will come for other kinds of execution units!

@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit 63e1d00 into main Nov 10, 2026
563 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the taegyunkim/profiling-span-link-key branch November 10, 2026 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/no-changelog A changelog entry is not required for this PR. Profiling Continous Profling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants