Skip to content

refactor: move helpers out of ddtrace.internal.runtime.__init__ - #19812

Open
emmettbutler wants to merge 2 commits into
mainfrom
emmett.butler/runtime-layering
Open

refactor: move helpers out of ddtrace.internal.runtime.__init__#19812
emmettbutler wants to merge 2 commits into
mainfrom
emmett.butler/runtime-layering

Conversation

@emmettbutler

Copy link
Copy Markdown
Collaborator

This change eliminates layering violations dependent on ddtrace.internal.runtime by moving the non-product-specific helper functions out of that module.

@emmettbutler
emmettbutler requested review from a team as code owners August 21, 2026 18:37
@emmettbutler emmettbutler added the changelog/no-changelog A changelog entry is not required for this PR. label Aug 21, 2026
@datadog-prod-us1-3

datadog-prod-us1-3 Bot commented Aug 21, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 7cf365a | Docs | View more details | Give us feedback!

@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: 640d257ccc

ℹ️ 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".

from .. import forksafe
from ddtrace.internal._runtime_id import get_ancestor_runtime_id
from ddtrace.internal._runtime_id import get_parent_runtime_id
from ddtrace.internal._runtime_id import get_process_role

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Update process-role mocks to patch the moved state

When the profiling suite runs test_uwsgi_postfork_worker_role_via_mock or test_uwsgi_main_role_via_mock, tests/profiling/test_process_role.py still calls monkeypatch.setattr(ddtrace.internal.runtime, "_PARENT_RUNTIME_ID", ...). This wrapper no longer defines that attribute, so both tests raise AttributeError before reaching their assertions; update those mocks to patch ddtrace.internal._runtime_id (where get_process_role now reads the state), or preserve compatible forwarding.

Useful? React with 👍 / 👎.

@datadog-prod-us1-3 datadog-prod-us1-3 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.

Datadog Autotest: FAIL

The move removes _PARENT_RUNTIME_ID from ddtrace.internal.runtime. Two profiling tests still patch that name, so they fail with AttributeError before their assertions.

Open Bits AI session

🤖 Datadog Autotest · Commit 640d257 · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest

from .. import forksafe
from ddtrace.internal._runtime_id import get_ancestor_runtime_id
from ddtrace.internal._runtime_id import get_parent_runtime_id
from ddtrace.internal._runtime_id import get_process_role

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Retarget process-role state mocks after the move

The profiling test suite fails, so the PR cannot complete required validation.

Assertion details
  • Input: Run test_uwsgi_postfork_worker_role_via_mock or test_uwsgi_main_role_via_mock in tests/profiling/test_process_role.py.
  • Expected: The profiling tests must patch _PARENT_RUNTIME_ID in ddtrace.internal._runtime_id, where the state now exists.
  • Actual: Both monkeypatch.setattr calls raise AttributeError because ddtrace.internal.runtime no longer has _PARENT_RUNTIME_ID. The tests stop before their assertions.

Was this helpful? React 👍 or 👎
🤖 Datadog Autotest · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest

@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/_runtime_id.py                                         @DataDog/apm-core-python
ddtrace/internal/core/crashtracking.py                                  @DataDog/profiling-python @DataDog/apm-core-python
ddtrace/internal/remoteconfig/client.py                                 @DataDog/remote-config @DataDog/apm-core-python
ddtrace/internal/runtime/__init__.py                                    @DataDog/apm-sdk-capabilities-python
ddtrace/internal/symbol_db/remoteconfig.py                              @DataDog/debugger-python
ddtrace/internal/symbol_db/symbols.py                                   @DataDog/debugger-python
ddtrace/internal/telemetry/writer.py                                    @DataDog/apm-python
ddtrace/internal/writer/writer.py                                       @DataDog/apm-core-python
tests/profiling/test_process_role.py                                    @DataDog/profiling-python

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Circular import analysis

⚠️ Existing circular imports

There are 3 circular imports that already exist on the base branch and have not been changed by this PR.

ddtrace.errortracking._handled_exceptions.bytecode_injector -> ddtrace.errortracking._handled_exceptions.callbacks -> ddtrace.errortracking._handled_exceptions.collector -> ddtrace.errortracking._handled_exceptions.bytecode_reporting -> ddtrace.errortracking._handled_exceptions.bytecode_injector
ddtrace.llmobs -> ddtrace.llmobs._evaluators -> ddtrace.llmobs._evaluators.format -> ddtrace.llmobs._experiment -> ddtrace.llmobs
ddtrace.appsec._asm_request_context -> ddtrace.appsec._iast._iast_request_context_base -> ddtrace.appsec._iast._iast_env -> ddtrace.appsec._iast.reporter -> ddtrace.appsec._exploit_prevention.stack_traces -> ddtrace.appsec._asm_request_context

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Dependency direction analysis

⚠️ Existing dependency direction violations

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

Show existing violations (showing 5 of 244 highest severity)
ddtrace.internal.tracemethods -×-> ddtrace.trace  (internal-core -> product:tracing, score=135)
ddtrace.llmobs._utils -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=133)
ddtrace.llmobs._integrations.google_adk -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=133)
ddtrace.llmobs._integrations.langchain -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=133)
ddtrace.llmobs._integrations.openai_agents -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=133)

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

✅ Dependency direction violations removed

6 violation(s) have been removed by this PR.

Show removed violations (showing 5 of 6 highest severity)
ddtrace.internal.symbol_db.remoteconfig -×-> ddtrace.internal.runtime  (internal-core -> product:runtime, score=14)
ddtrace.internal.remoteconfig.client -×-> ddtrace.internal.runtime  (internal-core -> product:runtime, score=14)
ddtrace.internal.writer.writer -×-> ddtrace.internal.runtime  (internal-core -> product:runtime, score=14)
ddtrace.internal.telemetry.writer -×-> ddtrace.internal.runtime  (internal-core -> product:runtime, score=14)
ddtrace.internal.core.crashtracking -×-> ddtrace.internal.runtime  (internal-core -> product:runtime, score=14)

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

@pr-commenter

pr-commenter Bot commented Aug 21, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-08-21 19:14:31

Comparing candidate commit 7cf365a in PR branch emmett.butler/runtime-layering with baseline commit cdf0aa0 in branch main.

📊 Benchmarking dashboard

Found 0 performance improvements and 10 performance regressions! Performance is the same for 605 metrics, 10 unstable metrics.

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 ----------------------------------'

scenario:httppropagationextract-wsgi_valid_headers_all

  • 🟥 execution_time [+413.220ns; +464.841ns] or [+7.647%; +8.602%]

scenario:httppropagationinject-ids_only

  • 🟥 execution_time [+1.824µs; +1.963µs] or [+9.593%; +10.326%]

scenario:iastaspects-casefold_noaspect

  • 🟥 execution_time [+30.538µs; +39.401µs] or [+12.470%; +16.089%]

scenario:iastaspects-join_aspect

  • 🟥 execution_time [+27.555µs; +30.374µs] or [+13.435%; +14.810%]

scenario:iastaspects-ljust_noaspect

  • 🟥 execution_time [+43.751µs; +49.432µs] or [+15.051%; +17.005%]

scenario:iastaspects-title_aspect

  • 🟥 execution_time [+37.774µs; +47.772µs] or [+13.997%; +17.702%]

scenario:iastaspectsospath-ospathbasename_aspect

  • 🟥 execution_time [+121.220µs; +127.524µs] or [+29.458%; +30.989%]

scenario:span-start

  • 🟥 execution_time [+1.318ms; +1.474ms] or [+8.801%; +9.845%]

scenario:telemetryaddmetric-1-count-metric-1-times

  • 🟥 execution_time [+313.059ns; +359.098ns] or [+11.730%; +13.455%]

scenario:tracer-small

  • 🟥 execution_time [+28.065µs; +30.038µs] or [+8.761%; +9.377%]

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 [-775.338ns; +707.825ns] or [-6.990%; +6.381%]

scenario:coreapiscenario-core_dispatch_1_listener

  • unstable execution_time [-31.887ns; +35.221ns] or [-5.227%; +5.774%]

scenario:coreapiscenario-core_dispatch_50_listeners

  • unstable execution_time [-1598.418ns; +1728.041ns] or [-9.381%; +10.141%]

scenario:coreapiscenario-core_dispatch_exception_listeners

  • unstable execution_time [-1452.647ns; +1057.400ns] or [-11.086%; +8.069%]

scenario:coreapiscenario-core_dispatch_listeners

  • unstable execution_time [-334.718ns; +317.786ns] or [-9.091%; +8.631%]

scenario:coreapiscenario-core_dispatch_no_args_listeners

  • unstable execution_time [-255.188ns; +255.328ns] or [-8.694%; +8.699%]

scenario:coreapiscenario-core_dispatch_with_results_1_listener

  • unstable execution_time [-71.565ns; +75.854ns] or [-6.185%; +6.555%]

scenario:coreapiscenario-core_dispatch_with_results_50_listeners

  • unstable execution_time [-4142.813ns; +3761.551ns] or [-10.250%; +9.307%]

scenario:coreapiscenario-core_dispatch_with_results_listeners

  • unstable execution_time [-617.990ns; +915.345ns] or [-7.664%; +11.352%]

scenario:packagesupdateimporteddependencies-import_many_stdlib_cached

  • unstable execution_time [-56.455µs; +64.938µs] or [-8.812%; +10.136%]

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant