Skip to content

refactor(internal): move the Python glue out of ddtrace.internal.native - #22138

Open
gnufede wants to merge 3 commits into
mainfrom
gnufede/package-split-native-glue
Open

gnufede wants to merge 3 commits into
mainfrom
gnufede/package-split-native-glue

Conversation

@gnufede

@gnufede gnufede commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Part of replacing #22018 with smaller PRs on main.

What

ddtrace/internal/native/ becomes the ddtrace-native package, which holds compiled code only and imports no
ddtrace Python module. This removes the Python glue that does not belong there:

  • get_configuration_from_disk() moves from native/__init__.py to settings/_core.py, its only caller, which
    already imports native and env. native/__init__.py no longer imports settings.env.
  • native/exceptions.py (is_panic_exception, plain Python) moves to ddtrace/internal/native_exceptions.py.
    Importing it no longer loads the Rust extension, which also removes the forksafe -> native -> forksafe
    import cycle.

The forksafe RNG reseed registration in native/__init__.py is left as is: #22125 replaces it with
pthread_atfork. Once both land, native/__init__.py only re-exports from _native.

Notes

  • Conflicts textually with refactor(native): reseed the RNG after fork from a native pthread_atfork handler #22125 on native/__init__.py (adjacent import lines). The resolution is to take
    both sides' deletions.
  • mypy, run on touched files, rejected an existing assignment to a parsed item in openfeature.py once
    _core.py was touched; _ParsedValues now declares __setattr__ under TYPE_CHECKING only.
  • Pulls in @DataDog/profiling-python through the import change in ddtrace/internal/core/crashtracking.py.

🤖 Generated with Claude Code

gnufede and others added 2 commits November 26, 2026 16:47
ddtrace.internal.native becomes the ddtrace-native package, which holds
compiled code only and imports no Python package. Its __init__ imported
settings.env for get_configuration_from_disk, so it could not ship as
is.

get_configuration_from_disk moves to settings._core, its only caller,
which already imports native and env. The forksafe reseed registration
in the same __init__ is left alone: #22125 replaces it.

mypy, run on the files a commit touches, rejected the existing
assignment to a parsed item in openfeature.py once _core.py was among
them. _ParsedValues declares __setattr__ for type checking only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ddtrace/internal/native/ becomes the ddtrace-native package, which holds
only compiled code. is_panic_exception is a plain Python helper used by
forksafe, packages and telemetry, which move to ddtrace-internal, and by
the tracer, the writers and crashtracking, so it moves next to them as
native_exceptions.

Importing it no longer loads the Rust extension as a side effect, which
also removes the forksafe -> native -> forksafe import cycle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gnufede gnufede added the changelog/no-changelog A changelog entry is not required for this PR. label Nov 26, 2026
@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/_trace/tracer.py                                                @DataDog/apm-sdk-capabilities
ddtrace/internal/core/crashtracking.py                                  @DataDog/profiling-python @DataDog/apm-core-python
ddtrace/internal/forksafe.py                                            @DataDog/apm-core-python
ddtrace/internal/native/__init__.py                                     @DataDog/apm-core-python
ddtrace/internal/native_exceptions.py                                   @DataDog/apm-core-python
ddtrace/internal/packages.py                                            @DataDog/apm-core-python
ddtrace/internal/settings/_core.py                                      @DataDog/apm-core-python
ddtrace/internal/telemetry/writer.py                                    @DataDog/apm-python
ddtrace/internal/writer/writer.py                                       @DataDog/apm-core-python
tests/internal/test_native.py                                           @DataDog/apm-core-python

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Dependency direction analysis

⚠️ Existing dependency direction violations

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

Show existing violations (showing 5 of 22 highest severity)
ddtrace.internal.tracemethods -×-> ddtrace.trace  (internal-core -> product:tracing, score=103)
ddtrace.llmobs._integrations.bedrock_agents -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=101)
ddtrace.llmobs._integrations.base -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=101)
ddtrace.internal.span_bus -×-> ddtrace._trace.span  (internal-core -> product:tracing, score=35)
ddtrace.llmobs._llmobs -×-> ddtrace._trace.span  (product:llmobs -> product:tracing, score=33)

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

@gnufede
gnufede marked this pull request as ready for review November 26, 2026 16:56
@gnufede
gnufede requested review from a team as code owners November 26, 2026 16:56
@gnufede
gnufede requested review from brettlangdon, taegyunkim and vpellan and removed request for a team November 26, 2026 16:56
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 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-26T17:00:30.732099Z d36a563 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.

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

Copy link
Copy Markdown
Contributor

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

The configuration-loader relocation preserves environment lookups and parsing behavior, and all panic-helper callers use the new module. Static review identified no actionable defect.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit d36a563

@pr-commenter

pr-commenter Bot commented Nov 26, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-11-26 17:29:07

Comparing candidate commit d36a563 in PR branch gnufede/package-split-native-glue with baseline commit 257b955 in branch main.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 614 metrics, 10 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 [-742.171ns; +744.569ns] or [-6.933%; +6.956%]

scenario:coreapiscenario-core_dispatch_1_listener

  • unstable execution_time [-39.302ns; +39.896ns] or [-6.148%; +6.241%]

scenario:coreapiscenario-core_dispatch_50_listeners

  • unstable execution_time [-1894.796ns; +1930.352ns] or [-9.491%; +9.669%]

scenario:coreapiscenario-core_dispatch_exception_listeners

  • unstable execution_time [-2038.025ns; +1642.489ns] or [-10.485%; +8.450%]

scenario:coreapiscenario-core_dispatch_listeners

  • unstable execution_time [-380.723ns; +374.864ns] or [-8.951%; +8.813%]

scenario:coreapiscenario-core_dispatch_no_args_listeners

  • unstable execution_time [-230.589ns; +226.430ns] or [-8.668%; +8.512%]

scenario:coreapiscenario-core_dispatch_with_results_1_listener

  • unstable execution_time [-100.426ns; +76.467ns] or [-7.333%; +5.583%]

scenario:coreapiscenario-core_dispatch_with_results_50_listeners

  • unstable execution_time [-4952.274ns; +4307.307ns] or [-10.191%; +8.863%]

scenario:coreapiscenario-core_dispatch_with_results_listeners

  • unstable execution_time [-1065.848ns; +806.509ns] or [-10.359%; +7.839%]

scenario:packagesupdateimporteddependencies-import_many_stdlib_cached

  • unstable execution_time [-66.254µs; +45.731µs] or [-11.259%; +7.771%]

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

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