Skip to content

refactor(internal): resolve the supported-configurations registry by pull - #22130

Open
gnufede wants to merge 9 commits into
mainfrom
gnufede/package-split-env
Open

gnufede wants to merge 9 commits into
mainfrom
gnufede/package-split-env

Conversation

@gnufede

@gnufede gnufede commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Part of replacing #22018 with smaller PRs on main.

settings/env.py imported the generated registry directly, which ties it to dd-trace-py. It is meant to move to
ddtrace-internal, which never imports ddtrace. This PR declares the registry as the ddtrace_internal.supported_configurations entry point and has env.py resolve it lazily on the first lookup that needs it (validation, aliases, sensitivity), cached afterwards. Nothing is registered at import time.

  • ddtrace/internal/utils/entry_points.py: shared, stdlib-only, Python 3.9-safe entry-point lookup (with declaring
    distributions). env is its first user; library identity and telemetry providers will reuse it.
  • env.py: register_supported_configurations() stays as an explicit override (first registration wins). A missing or
    failing entry point is logged once and means "unregistered". No lock: racing threads load the same module and install the same values, and the registry marker is assigned last. Adds get_aliases(name) / is_sensitive(name); telemetry keeps reading the registry directly (adopting them is a separate PR).
  • scripts/supported_configurations.py: the supported-config check also scans the installed split packages' sources
    (ported from chore(package-split): prepare dd-trace-py for moving code into packages #22018, with the test fixes).
  • Freezes settings/env.py and settings/__init__.py (wave-1 files).

Tests: tests/internal/test_env.py, tests/internal/test_entry_points.py,
tests/internal/test_supported_configurations_script.py.

🤖 Generated with Claude Code

gnufede and others added 8 commits November 26, 2026 16:43
Code moving to ddtrace-internal will pull what dd-trace-py provides
through entry points instead of having ddtrace/__init__.py push it at
import. Consumers need the declaring distribution as well as the entry
point, to read a name and version from metadata without importing
anything, but EntryPoint.dist only exists from Python 3.10.

Keep that version split in one stdlib-only helper so the supported-
configurations registry, the library identity and the telemetry
providers share it, and so settings.env, which loads before the logger,
can use it too.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…pull

settings.env imported the generated registry directly, which ties it to
dd-trace-py: it is meant to move to ddtrace-internal, which never
imports ddtrace. Declare the registry as the
ddtrace_internal.supported_configurations entry point instead and let
env.py resolve it lazily on the first lookup that needs it (validation,
aliases or sensitivity), caching the result.

An explicit register_supported_configurations() call made before that
lookup still wins, the first registration taking effect. A missing or
failing entry point is logged once and behaves as unregistered. There is
no lock: racing threads load the same module and install the same
values, and the registry marker is assigned last.

Also expose get_aliases() and is_sensitive() for shared code. Telemetry
keeps reading the registry directly for now.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Env var reads are moving out of ddtrace/ into the _ddtrace_internal and
_ddtrace_coverage packages. The registry check only walked ddtrace/**,
so a var added inside a package would never be checked against
supported-configurations.json.

Also scan the installed sources of the split packages, located with
importlib.util.find_spec. Packages that are not installed are skipped,
so the result is unchanged today. The scanned roots are printed, and
constants imported from a split package are resolved for envier names.

The script's pre-existing mypy errors are fixed too, since the mypy
pre-commit hook blocks any commit that touches it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
(cherry picked from commit 16b2e95)
…nternal

test_package_source_roots_finds_installed_package stages a fake
_ddtrace_internal and expects find_spec to locate it. Now that ddtrace
pins ddtrace-internal, tests/conftest has already imported the real
one, so find_spec returned the installed copy. Drop it from
sys.modules for the duration of the test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 0690613)
check_registry() scans the dd-trace-py checkout and reads
ddtrace/_monkey.py. CI runs the internal suite against an installed
ddtrace, without the checkout's ddtrace/ directory, so the four tests
calling it failed with FileNotFoundError. Skip just those when the
sources are absent; the package discovery tests still run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 7458f48)
The previous commit skipped these tests when ddtrace/_monkey.py is
absent, which is always the case in CI (the internal suite runs
against an installed ddtrace), so they would never run there.

Move the PATCH_MODULES parsing into _patch_modules() and have the
tests point REPO_ROOT at an empty temporary checkout with a stubbed
integration list. The tests now exercise the scan without needing the
dd-trace-py sources; the real check still reads them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 238b9fa)
…split packages

The installed-package scan test only faked _ddtrace_internal, so when the
bridge final state installs several split packages side by side (e.g.
ddtrace-coverage next to ddtrace-internal), the genuinely installed
_ddtrace_coverage in site-packages also showed up in _package_source_roots()
and the single-package assertion failed. The scan is working as designed;
the test's isolation predates a second installed split package.

Fake every package in SPLIT_PACKAGES in tmp_path instead of one, and assert
the scan resolves each name to its fake root, in SPLIT_PACKAGES order. The
fakes are regular packages first on sys.path, so find_spec shadows the
installed copies and the assertion holds in any environment.

(cherry picked from commit c581b11)
settings/env.py and settings/__init__.py move to ddtrace-internal once
the prep is complete. Freeze them so the move stays a pure relocation.

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
@gnufede gnufede changed the title Title refactor(internal): resolve the supported-configurations registry by pull Nov 26, 2026
@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.base -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=101)
ddtrace.llmobs._integrations.bedrock_agents -×-> 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

@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/settings/env.py                                        @DataDog/apm-sdk-capabilities
ddtrace/internal/utils/entry_points.py                                  @DataDog/apm-core-python
frozen-paths.txt                                                        @DataDog/apm-core-python
pyproject.toml                                                          @DataDog/apm-python-guild
scripts/supported_configurations.py                                     @DataDog/apm-sdk-capabilities
tests/internal/test_entry_points.py                                     @DataDog/apm-core-python
tests/internal/test_env.py                                              @DataDog/apm-sdk-capabilities
tests/internal/test_supported_configurations_script.py                  @DataDog/apm-core-python

@datadog-prod-us1-5

datadog-prod-us1-5 Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Pipelines  Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

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

@pr-commenter

pr-commenter Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-11-26 17:32:23

Comparing candidate commit bed915c in PR branch gnufede/package-split-env with baseline commit 257b955 in branch main.

📊 Benchmarking dashboard

Found 0 performance improvements and 1 performance regressions! Performance is the same for 618 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 ----------------------------------'

scenario:codeprovenancefork-fork-10

  • 🟥 execution_time [+122.426ms; +128.516ms] or [+7.163%; +7.519%]

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 [-748.755ns; +720.893ns] or [-7.015%; +6.754%]

scenario:coreapiscenario-core_dispatch_1_listener

  • unstable execution_time [-30.350ns; +44.782ns] or [-4.738%; +6.992%]

scenario:coreapiscenario-core_dispatch_50_listeners

  • unstable execution_time [-1946.828ns; +1886.615ns] or [-9.748%; +9.447%]

scenario:coreapiscenario-core_dispatch_exception_listeners

  • unstable execution_time [-2038.176ns; +1613.566ns] or [-10.485%; +8.301%]

scenario:coreapiscenario-core_dispatch_listeners

  • unstable execution_time [-371.638ns; +381.914ns] or [-8.738%; +8.980%]

scenario:coreapiscenario-core_dispatch_no_args_listeners

  • unstable execution_time [-220.242ns; +231.906ns] or [-8.289%; +8.728%]

scenario:coreapiscenario-core_dispatch_with_results_1_listener

  • unstable execution_time [-106.774ns; +69.414ns] or [-7.690%; +4.999%]

scenario:coreapiscenario-core_dispatch_with_results_50_listeners

  • unstable execution_time [-4927.283ns; +4295.162ns] or [-10.162%; +8.858%]

scenario:coreapiscenario-core_dispatch_with_results_listeners

  • unstable execution_time [-1178.608ns; +706.779ns] or [-11.447%; +6.865%]

scenario:packagesupdateimporteddependencies-import_many_stdlib_cached

  • unstable execution_time [-62.242µs; +50.885µs] or [-10.559%; +8.632%]

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:10
@gnufede
gnufede requested review from a team as code owners November 26, 2026 17:10
@gnufede
gnufede requested review from Mascarpone, juanjux and yaronguro-datadog and removed request for a team November 26, 2026 17:10
@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:16:25.662963Z bed915c 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-prod-us1-5 datadog-prod-us1-5 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

Lazy registry resolution preserves explicit-registration precedence and exact-key reads when no provider is available. Runtime behavior and startup cost remain unmeasured.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit bed915c

@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: bed915c787

ℹ️ 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 +98 to +101
# `_resolving` guards against re-entry (e.g. the load triggers an env lookup).
if _resolved or _resolving:
return
_resolving = True

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 Distinguish concurrent resolution from same-thread re-entry

If two threads perform their first configuration lookup concurrently, the second sees _resolving and returns before the first finishes loading the registry. That lookup consequently ignores registered aliases—for example, reading DD_REQUESTS_SERVICE misses a configured DD_REQUESTS_SERVICE_NAME—and can cache a default instead. Assigning the registry marker last does not prevent incomplete reads. Distinguish recursion by the resolving thread from concurrent callers, while preserving complete registry semantics for the latter.

Useful? React with 👍 / 👎.

try:
if _SUPPORTED_CONFIGURATIONS is None:
try:
module = _load_entry_point_module(ENTRY_POINT_GROUP)

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 registry lookup on the startup path

The first environment lookup now discovers the registry through importlib.metadata.entry_points(), adding installed-distribution metadata discovery to startup instead of directly importing the generated registry. The supplied commit records functional tests but provides no startup benchmark results. AGENTS.md explicitly requires benchmarks for startup changes; run run-benchmarks against the parent revision and report the comparison, including an environment with many installed distributions.

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

Useful? React with 👍 / 👎.

Comment on lines +68 to +69
for entry_point, _ in entry_points_with_distributions(group):
return entry_point.load()

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 Validate registry providers before loading their entry points

If an installed third-party distribution declares this group and is discovered before ddtrace, its module is executed during ordinary import ddtrace: logger initialization performs an environment lookup that reaches this loader. Discarding the declaring distribution and unconditionally calling load() bypasses the distribution/module trust checks in ddtrace/internal/entry_points.py:is_trusted, which both product and integration-hook discovery enforce to prevent automatic loading of third-party plugins. Apply equivalent trusted-distribution and module-namespace checks here, skipping untrusted providers before calling load().

Useful? React with 👍 / 👎.

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