Skip to content

[prototype] package split phase 1: bridge to ddtrace-internal and ddtrace-coverage - #21992

Draft
gnufede wants to merge 24 commits into
mainfrom
gnufede/split-prototype-phase1
Draft

gnufede wants to merge 24 commits into
mainfrom
gnufede/split-prototype-phase1

Conversation

@gnufede

@gnufede gnufede commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Description

Prototype for discussion, not for merge. This is Phase 1 of a local end-to-end prototype of the package split, for the team to review before the real PRs land. It pairs with DataDog/datadog-apm-python#81 (ddtrace-internal additions plus the new ddtrace-coverage package). Plan: DataDog/datadog-apm-python#80. Phase 2 (switching to ddtrace-native) is #21993, stacked on this one.

Contents:

  • Merged prerequisites:
  • Bridges. Each moved module becomes a runtime swap to the package module (sys.modules[__name__] = import_module(...)), plus a TYPE_CHECKING re-export block for mypy. As a result, ddtrace.internal.X is _ddtrace_internal.X for env, logger, module, compat, cache, paths, obfuscation and time, and for every coverage module, so there's a single copy of state.
  • Partially moved modules (utils/__init__, utils/formats, utils/inspection, bytecode_injection/__init__) import the moved names and keep the rest.
  • The registry is registered with _ddtrace_internal.settings.env from ddtrace/__init__.py.
  • A test fix: a source-scanning test (test_compat_version_bounds.py) now reads the moved coverage sources from _ddtrace_coverage.
  • Dependencies: ddtrace-internal==0.4.0.dev0 and ddtrace-coverage==0.1.0.dev0. These aren't published, so CI here will fail to resolve them. The prototype was run with locally built wheels.

Testing

Docker test environments, Python 3.12, compared with the same environments on main (1481176660):

Suite main prototype
coverage 148 passed 149 passed
ci_visibility 654 passed 654 passed
ci_visibility snapshots 15 15
testing 1 failure (pre-existing) same 1 failure
internal 3329 passed 3332 passed
debugger / wrapping / unittest / package_split 640 / 334 / 45 / 63 same
tracer 22 failures (pre-existing) same 22

Risks / what the real PRs need

  1. Logger names. Package loggers (_ddtrace_internal.*, ...) aren't under ddtrace. That's fixed separately in chore(logging): apply the ddtrace logger config to package loggers #21987, which also keeps the _DD_<PRODUCT>_LOG_LEVEL names.
  2. Bridge style. from X import * loses private names and anything not in __all__. Use importlib.import_module, never import a.b as x: settings.env is shadowed by an attribute with the same name.
  3. Supported-config scan. It goes blind to env vars read inside the packages. That's fixed in chore(lint): scan split packages in the supported-config check #21988.
  4. wrapt typing. ddtrace-internal depends on wrapt, so adding it to the lint group pulls wrapt into mypy's environment. Every wrapt 2.x ships type information (inline py.typed in 2.0–2.1, wrapt-stubs from 2.2), which causes 47 errors on the full tree. This prototype pins wrapt<2 in the lint group, so mypy keeps seeing an untyped wrapt as it does today. wrapt 1.x is within the runtime range and still tested. The proper typing fix is chore(typing): type wrapt proxies so mypy passes with wrapt installed #21989.
  5. Bridge type blocks must list every imported name. Each bridge's TYPE_CHECKING block falls back to a module __getattr__, so a missing name is typed Any instead of failing. compat lacked singledispatchmethod, which made symbol_db's decorators untyped, and the coverage bridges declared nothing. Fixed here. Full mypy is clean on all 1243 files; the commit hooks alone miss this, because they only check staged files.
  6. Freeze lists must include the partially moved files, and coverage. See chore(package-split): freeze quiet coverage files #21990.

🤖 Generated with Claude Code

gnufede and others added 23 commits November 12, 2026 18:43
ddtrace.internal.codeowners has been extracted to datadog-apm-python as
_ddtrace_internal_base.codeowners (published as ddtrace-internal-base).
Replace the vendored implementation with a bridge that re-exports the
extracted package, so there is a single source of truth. The bridge fails
loudly if the package is missing; the vendored code remains in git history.

Also pin the package in the lint dependency group: mypy runs with
--only-group lint, and without the installed package
ignore_missing_imports=true would silently degrade Codeowners to Any
downstream (e.g. bdd.py returning-Any).

Verified locally with a wheel built from datadog-apm-python: internal,
ci_visibility::testing, and detect_global_locks suites pass, along with
scripts/lint checks.
The extracted module moved: datadog-apm-python absorbed
ddtrace-internal-base into ddtrace-internal, so the bridge imports
_ddtrace_internal.codeowners and the dependency it needs is one ddtrace
already has, at a newer version.

That makes this a version bump rather than a new dependency:
ddtrace-internal goes from 0.2.0 to 0.3.0, the release that carries
codeowners, and ddtrace-internal-base disappears from the runtime
dependencies, the lint group and both requirements CSVs. The release
note says the same -- mirrors must carry the new version, not a new
distribution.

CSVs regenerated with scripts/requirements_to_csv.py.
The aws_lambda suite depends on datadog-lambda, which transitively
depends on the released ddtrace, so its environment lock pins the full
transitive closure, including ddtrace-internal. scripts/run-tests
strips the ddtrace pin when installing the locally built ddtrace, but
keeps the ddtrace-internal pin, which must match the local wheel's
requirement. With the bridge pointing at ddtrace-internal 0.3.0, the
stale 0.2.0 pin made the env build unsatisfiable (uv exit 1 for
6abbc5115929, Python 3.15 job).

Same manual bump as 96e3c67 (ddtrace-internal 0.1.0 -> 0.2.0). The pin
will track 0.3.0 again naturally once a released ddtrace that requires
ddtrace-internal 0.3.0 is past the lock cooldown.
Coverage imported ddtrace.internal.packages only for the four sysconfig
paths it excludes by default (stdlib, platstdlib, platlib, purelib).
That import pulls in about 23 ddtrace modules, including the native
extension, threads and uwsgi, which coverage otherwise does not need.

Resolve the same four paths with sysconfig, exactly as packages.py
does, so coverage can later be extracted into its own package without
dragging that machinery along. A test pins the result to the values
packages.py computes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The pytest plugin and the BDD plugin imported ddtrace, and the logging
and selenium contrib patches, directly. Move those touchpoints behind
lazy helpers in tracer_api/context.py (get_tracer, enable_log_correlation,
enable_selenium_integration), next to the existing trace filter and
patch-all helpers.

No behavior change. It makes tracer_api the single seam between test
optimization and the tracer, so the plugin can later be extracted into
its own package with the tracer integration injected by dd-trace-py.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Every other ddtrace.testing module logs through logging.getLogger; the
xdist helpers were the exception, importing ddtrace.internal.logger.
Its extras (product rate limiting, ddtrace.* level lookup) do not apply
to this module's records, so the stdlib logger is equivalent here and
drops one more ddtrace internal from the plugin.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
With tracer integration off, a pytest session must not make
ddtrace.testing import the tracer, _monkey or the logging/selenium
contrib. sys.modules cannot show this in-tree, since importing
ddtrace.testing runs ddtrace/__init__, so the test records imports by
importer. Positive controls cover tracer integration on and
--ddtrace-patch-all.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The module created a logger it never used. Removing it makes
ddtrace.internal.utils.time stdlib-only, so it can move to the
ddtrace-internal package alongside the other shared utilities
(coverage and test optimization both use StopWatch).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…th env

Package split: ddtrace.internal.settings.env and ddtrace.internal.logger
move to the ddtrace-internal package, while the generated registry
(supported-configurations.json, its generator, hook and lint check) stays
in dd-trace-py so adding a config remains a dd-trace-py-only change.

env no longer imports _supported_configurations. It exposes
register_supported_configurations(), first registration wins, and
ddtrace/__init__.py calls it before anything else is imported. Python runs
the package __init__ before any submodule, so registration precedes every
env lookup. Before registration env is inert: no key validation (no debug
log) and no aliases, i.e. exact-key lookups in os.environ.

Behavior once ddtrace is imported is unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
ddtrace-internal 0.4.0 depends on wrapt, so the lint environment (which
installs ddtrace-internal) now gets wrapt with its type stubs, and mypy
starts reporting ObjectProxy generics in forksafe and safety. Ignore
them at the two call sites; no behaviour change.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Alias settings.env, logger, module, compat, assembly, utils.cache,
utils.paths, utils.obfuscation, utils.time, bytecode_injection.core and
every ddtrace.internal.coverage module to their package counterparts
(sys.modules replacement at runtime, static re-exports for mypy), and
import the moved names into the modules that keep other code (utils,
utils.formats, utils.inspection, bytecode_injection). ddtrace/__init__
registers the supported-configurations registry with
_ddtrace_internal.settings.env directly. Depend on ddtrace-internal
0.4.0.dev0 and ddtrace-coverage 0.1.0.dev0.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
uv pip install runs inside the testrunner container, which cannot see
the host's /tmp or any index carrying the 0.x.dev0 builds. Point uv at
the wheels copied into the (git-ignored) .cache/split-wheels. Never
upstream.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
`import _ddtrace_internal.settings.env as _impl` resolves the final
component by attribute access, and the settings package re-exports
dd_environ as `env`, shadowing the submodule: the bridge then replaced
itself with the EnvConfig instance. Use importlib.import_module, which
reads sys.modules.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
test_py315_feature_gate_does_not_follow_next_max parses the sources of
the modules that gate on is_at_least_py(3, 15). The coverage ones are
bridges now, so read them from the _ddtrace_coverage package instead.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@cit-pr-commenter-54b7da

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

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/__init__.py                                                     @DataDog/apm-python-guild
ddtrace/internal/assembly.py                                            @DataDog/apm-core-python
ddtrace/internal/bytecode_injection/__init__.py                         @DataDog/apm-core-python
ddtrace/internal/bytecode_injection/core.py                             @DataDog/apm-core-python
ddtrace/internal/codeowners.py                                          @DataDog/ci-app-libraries
ddtrace/internal/compat.py                                              @DataDog/apm-python-guild @DataDog/apm-core-python
ddtrace/internal/coverage/code.py                                       @DataDog/ci-app-libraries
ddtrace/internal/coverage/context_state.py                              @DataDog/ci-app-libraries
ddtrace/internal/coverage/coverage_lines.py                             @DataDog/ci-app-libraries
ddtrace/internal/coverage/import_instrumentation_py3_12.py              @DataDog/ci-app-libraries
ddtrace/internal/coverage/installer.py                                  @DataDog/ci-app-libraries
ddtrace/internal/coverage/instrumentation.py                            @DataDog/ci-app-libraries
ddtrace/internal/coverage/instrumentation_py3_10.py                     @DataDog/ci-app-libraries
ddtrace/internal/coverage/instrumentation_py3_11.py                     @DataDog/ci-app-libraries
ddtrace/internal/coverage/instrumentation_py3_12.py                     @DataDog/ci-app-libraries
ddtrace/internal/coverage/instrumentation_py3_16.py                     @DataDog/ci-app-libraries
ddtrace/internal/coverage/instrumentation_py3_9.py                      @DataDog/ci-app-libraries
ddtrace/internal/coverage/instrumented_mode.py                          @DataDog/ci-app-libraries
ddtrace/internal/coverage/mode.py                                       @DataDog/ci-app-libraries
ddtrace/internal/coverage/multiprocessing_coverage.py                   @DataDog/ci-app-libraries
ddtrace/internal/coverage/report.py                                     @DataDog/ci-app-libraries
ddtrace/internal/coverage/threading_coverage.py                         @DataDog/ci-app-libraries
ddtrace/internal/coverage/util.py                                       @DataDog/ci-app-libraries
ddtrace/internal/logger.py                                              @DataDog/apm-core-python
ddtrace/internal/module.py                                              @DataDog/debugger-python @DataDog/apm-core-python
ddtrace/internal/settings/env.py                                        @DataDog/apm-sdk-capabilities
ddtrace/internal/utils/__init__.py                                      @DataDog/apm-core-python
ddtrace/internal/utils/cache.py                                         @DataDog/apm-core-python
ddtrace/internal/utils/formats.py                                       @DataDog/apm-core-python
ddtrace/internal/utils/inspection.py                                    @DataDog/apm-core-python
ddtrace/internal/utils/obfuscation.py                                   @DataDog/apm-core-python
ddtrace/internal/utils/paths.py                                         @DataDog/apm-core-python
ddtrace/internal/utils/time.py                                          @DataDog/apm-core-python
ddtrace/testing/internal/pytest/bdd.py                                  @DataDog/ci-app-libraries
ddtrace/testing/internal/pytest/plugin.py                               @DataDog/ci-app-libraries
ddtrace/testing/internal/pytest/xdist.py                                @DataDog/ci-app-libraries
ddtrace/testing/internal/tracer_api/context.py                          @DataDog/ci-app-libraries
lib-injection/sources/requirements.csv                                  @DataDog/apm-core-python
pyproject.toml                                                          @DataDog/apm-python-guild
releasenotes/notes/codeowners-from-ddtrace-internal-89c41a5421721371.yaml  @DataDog/apm-python
requirements.csv                                                        @DataDog/apm-python-guild
tests/coverage/test_coverage.py                                         @DataDog/ci-app-libraries
tests/internal/test_codeowners.py                                       @DataDog/ci-app-libraries
tests/internal/test_compat_version_bounds.py                            @DataDog/apm-core-python
tests/internal/test_env.py                                              @DataDog/apm-sdk-capabilities
tests/requirements_locks/6abbc5115929.txt                               @DataDog/apm-python
tests/testing/internal/test_tracer_isolation.py                         @DataDog/ci-app-libraries

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Nov 20, 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

@datadog-official

datadog-official Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Pipelines  Tests

❌ Errors

Your PR has failed checks. Please review the issues below and take necessary action before merging.

🚦 75 Pipeline jobs failed

DataDog/apm-reliability/dd-trace-py | ast-grep rules

View more details · View in GitLab

DataDog/apm-reliability/dd-trace-py | build linux serverless: [amd64, cp310-cp310, v133965497-8f84bce-musllinux_1_2_x86_64, 1]

View more details · View in GitLab

DataDog/apm-reliability/dd-trace-py | build linux serverless: [amd64, cp310-cp310, v133965508-8f84bce-manylinux2014_x86_64, 1]

View more details · View in GitLab

View all 75 failed jobs.

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

Useful? React with 👍 / 👎

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

ddtrace-internal depends on wrapt, so pinning it in the lint group
pulled wrapt into mypy's environment. Every wrapt 2.x ships type
information (inline py.typed in 2.0-2.1, wrapt-stubs from 2.2), which
mypy then checks our wrapt usage against: 47 errors once the whole
tree is checked. Pin wrapt<2 in the lint group so mypy keeps seeing an
untyped wrapt, as it did before the bridge; wrapt 1.x is within the
runtime range and still tested. This replaces the four type-ignores
added earlier in this branch, which only covered the files the commit
hooks had checked. The proper typing fix is #21989.

The bridges' TYPE_CHECKING blocks fall back to a module __getattr__, so
any name missing from them is typed Any instead of failing. compat
lacked singledispatchmethod (which made every @singledispatchmethod in
symbol_db an untyped decorator), and the coverage bridges declared no
names at all. Re-export every name dd-trace-py imports from them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant