Skip to content

chore(internal): keep package modules at bootstrap and find the third-party list per package - #22135

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

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

Conversation

@gnufede

@gnufede gnufede commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Description

Part of replacing #22018 with smaller PRs on main. Two commits, ported verbatim:

  1. cleanup_loaded_modules() keeps every _ddtrace_* module, like ddtrace's own. Once a module is bridged, ddtrace.internal.X is the same object as _ddtrace_internal.X; dropping the package key made the next import create a second copy with empty state (registry, ModuleWatchdog, logger), and a pyo3 module cannot be initialised twice. No _ddtrace_* modules are loaded on main, so this is a no-op today: no release note. Test in tests/internal/test_auto.py.
  2. packages.py reads third-party.tar.gz from its own package (__name__.rpartition(".")[0]) instead of hardcoded ddtrace.internal, so it stays right once it moves to ddtrace-internal. Still resolves to ddtrace.internal here.

Testing

tests/internal (3.12; includes test_auto.py): 3357 passed. Commit hooks passed.

🤖 Generated with Claude Code

gnufede and others added 2 commits November 26, 2026 17:02
cleanup_loaded_modules() drops every module ddtrace imported except
ddtrace's own. Once a module is bridged, ddtrace.internal.X is the same
object as _ddtrace_internal.X, and the cleanup kept the ddtrace key but
dropped the package one. The next import of the package module (e.g.
from _ddtrace_coverage) then made a second copy with empty state (the
supported-configurations registry, ModuleWatchdog, logger state), and a
pyo3 module cannot be initialized twice at all. Keep every _ddtrace_*
module, like ddtrace's own. No such modules are loaded today, so this is
a no-op until the first bridge and not user visible.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…e's package

packages.py read third-party.tar.gz from the hardcoded "ddtrace.internal"
package. Resolving it from the module's own package keeps the lookup
right once packages.py and its data file move to ddtrace-internal, so
the port stays verbatim. In dd-trace-py it still resolves to
ddtrace.internal.

Co-Authored-By: Claude Sonnet 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/bootstrap/cloning.py                                            @DataDog/apm-python-guild @DataDog/apm-core-python
ddtrace/internal/packages.py                                            @DataDog/apm-core-python
tests/internal/test_auto.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

@pr-commenter

pr-commenter Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-11-26 17:45:54

Comparing candidate commit 1fd5d43 in PR branch gnufede/package-split-bootstrap with baseline commit 257b955 in branch main.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 601 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 [-740.630ns; +732.856ns] or [-6.941%; +6.868%]

scenario:coreapiscenario-core_dispatch_1_listener

  • unstable execution_time [-38.251ns; +40.937ns] or [-5.991%; +6.411%]

scenario:coreapiscenario-core_dispatch_50_listeners

  • unstable execution_time [-1950.716ns; +1886.562ns] or [-9.744%; +9.423%]

scenario:coreapiscenario-core_dispatch_exception_listeners

  • unstable execution_time [-2056.016ns; +1644.177ns] or [-10.608%; +8.483%]

scenario:coreapiscenario-core_dispatch_listeners

  • unstable execution_time [-373.011ns; +384.328ns] or [-8.787%; +9.054%]

scenario:coreapiscenario-core_dispatch_no_args_listeners

  • unstable execution_time [-230.757ns; +225.244ns] or [-8.667%; +8.460%]

scenario:coreapiscenario-core_dispatch_with_results_1_listener

  • unstable execution_time [-99.945ns; +76.726ns] or [-7.224%; +5.546%]

scenario:coreapiscenario-core_dispatch_with_results_50_listeners

  • unstable execution_time [-5201.060ns; +4097.792ns] or [-10.642%; +8.385%]

scenario:coreapiscenario-core_dispatch_with_results_listeners

  • unstable execution_time [-997.091ns; +895.505ns] or [-9.635%; +8.654%]

scenario:packagesupdateimporteddependencies-import_many_stdlib_cached

  • unstable execution_time [-55.224µs; +57.276µs] or [-9.420%; +9.770%]

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

@gnufede
gnufede marked this pull request as ready for review November 26, 2026 17:19
@gnufede
gnufede requested review from a team as code owners November 26, 2026 17:19
@gnufede
gnufede requested review from danielsn and emmettbutler and removed request for a team November 26, 2026 17:19
@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:22:18.072010Z 1fd5d43 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: 1fd5d4396e

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

Comment on lines +92 to +93
if m.startswith("_ddtrace_"):
continue

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Benchmark the changed bootstrap cleanup path

When module unloading is enabled, this adds a prefix check to the startup module-cleanup loop. The supplied validation lists correctness tests and commit hooks but no startup benchmark results. Run the run-benchmarks skill against the parent and record the startup comparison to satisfy the explicit benchmark requirement in AGENTS.md; correctness tests do not cover startup performance.

AGENTS.md reference: AGENTS.md:L16-L18

Useful? React with 👍 / 👎.

@datadog-prod-us1-4 datadog-prod-us1-4 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 archive lookup still resolves to ddtrace.internal at this revision, and bootstrap cleanup preserves extracted package modules alongside their ddtrace aliases. The completed static review identified no actionable defects.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 1fd5d43

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