Repository navigation
Conversation
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>
Dependency direction analysis
|
Codeowners resolved asResolved from the full PR diff against |
🎉 All green!🧪 All tests passed 🔗 Commit SHA: bed915c | Docs | View more details | Give us feedback! |
BenchmarksBenchmark execution time: 2026-11-26 17:32:23 Comparing candidate commit bed915c in PR branch Found 0 performance improvements and 1 performance regressions! Performance is the same for 618 metrics, 10 unstable metrics, 1 flaky benchmarks without significant changes.
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
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.
🤖 Bits Code Review · Commit bed915c
There was a problem hiding this comment.
💡 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".
| # `_resolving` guards against re-entry (e.g. the load triggers an env lookup). | ||
| if _resolved or _resolving: | ||
| return | ||
| _resolving = True |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 👍 / 👎.
| for entry_point, _ in entry_points_with_distributions(group): | ||
| return entry_point.load() |
There was a problem hiding this comment.
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 👍 / 👎.
Part of replacing #22018 with smaller PRs on
main.settings/env.pyimported the generated registry directly, which ties it to dd-trace-py. It is meant to move toddtrace-internal, which never importsddtrace. This PR declares the registry as theddtrace_internal.supported_configurationsentry point and hasenv.pyresolve 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 declaringdistributions).
envis 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 orfailing 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).
settings/env.pyandsettings/__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