Skip to content

chore(package-split): prepare dd-trace-py for moving code into packages - #22018

Open
gnufede wants to merge 34 commits into
mainfrom
gnufede/package-split-prep
Open

gnufede wants to merge 34 commits into
mainfrom
gnufede/package-split-prep

Conversation

@gnufede

@gnufede gnufede commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Description

Prepares dd-trace-py for moving code into packages released from DataDog/datadog-apm-python (plan: DataDog/datadog-apm-python#80). Every change preserves behavior. The goal is that dd-trace-py's layout already shows where each piece of code is going, and that the code being moved no longer reaches into the tracer.

Target layout

Today in dd-trace-py Goes to Rule
ddtrace/internal/native/ (Rust _native, plus _msgpack and _threads) ddtrace-native compiled code only; imports no Python package
shared Python code in ddtrace/internal/ ddtrace-internal may import ddtrace-native, never ddtrace
ddtrace/internal/coverage/ ddtrace-coverage
ddtrace/testing/ ddtrace-testing (later)

What changes

  • Settings and logging.
    • env gets the supported-configurations registry (with aliases and sensitive names) from ddtrace/__init__.py instead of importing it.
    • get_logger logs package code under its former ddtrace.* name, so log names, handlers and _DD_<PRODUCT>_LOG_LEVEL are unchanged. This also fixes order-dependent level resolution and % arguments being formatted after the exception text.
    • Moving modules that log through stdlib logging use the same normalization as logging.getLogger(logger_name(__name__)). settings.env can't import the logger, so it spells its name out.
    • The logger setup moves to ddtrace/internal/logger_setup.py.
  • Native package.
    • The generic msgpack packer moves out of _encoding into native/_msgpack, and _threads moves into native/.
    • The Rust code imports the _msgpack next to it, so it no longer imports ddtrace and _register_packb is gone.
    • native/__init__.py now only re-exports. The fork reseed hook is registered in ddtrace/__init__.py, and the Python helper native/exceptions.py moves out to native_exceptions.py.
    • scripts/lint native-import-check enforces this.
    • ddtrace.internal._threads stays as a temporary alias for now.
  • Telemetry. It receives the library name, version, code roots and integration resolver through ddtrace/internal/telemetry_inputs/ instead of importing them. This also fixes error attribution, which would have missed _ddtrace_* paths.
  • packages.py finds its third-party.tar.gz data from its own package instead of the hardcoded ddtrace.internal.
  • Test optimization.
    • Its tracer touchpoints go through tracer_api.
    • The ci_visibility helpers it used, and the coverage.py logic, move into ddtrace.testing; contrib.internal.coverage stays as a thin integration.
    • Importing the pytest plugin loads no tracer modules, which a test asserts.
    • Test events take library_version from the version registered with telemetry, which is ddtrace's, so they're unchanged.
  • Coverage computes its default exclude paths with sysconfig.
  • Constants. The sampling priorities and the env/version tag keys are defined in internal/constants, and ddtrace.constants re-exports them unchanged.
  • Bootstrap. cleanup_loaded_modules() keeps _ddtrace_* modules, so bridged modules aren't imported twice.
  • Freeze. frozen-paths.txt freezes the 33 files ported in this wave: 15 to ddtrace-internal 0.4.0 (DataDog/datadog-apm-python#77) and 18 to ddtrace-coverage (DataDog/datadog-apm-python#82). Each package's bridge PR removes its entries.

Testing

  • Locally (Docker, Python 3.12, on the branches merged here), the tracer, internal, telemetry, appsec, testing, ci_visibility, coverage, debugging, profiling and vendor suites showed no failures beyond those on the base branch.
  • New tests cover:
    • the relocated _msgpack and _threads binaries, loaded without ddtrace;
    • the fork reseed under import ddtrace, ddtrace.auto and ddtrace-run;
    • logger names and levels;
    • the bootstrap cleanup;
    • telemetry inputs and error attribution;
    • the tracer isolation of test optimization;
    • the unchanged ddtrace.constants namespace.
  • A local end-to-end test of the final layout bridged this branch to all four packages: ddtrace-internal (with the shared runtime), ddtrace-coverage, ddtrace-native and a prototype ddtrace-testing. On Python 3.13 every suite matched the base branch by failing test ID, and pytest ran with the plugin without ddtrace installed. The last four changes (logger names, native_exceptions, the packages.py data lookup, the test-event version) came out of it.
  • mypy, native-import-check, supported-config-check, layers and suitespec checks pass. packb and the encoders benchmark within noise.

Risks

  • ddtrace/__init__.py now registers the configuration registry, the reseed hook and the telemetry inputs before anything else, so forksafe, native and utils.version load earlier.
  • Package code must use get_logger or logger_name. A plain logging.getLogger(__name__) isn't normalized.
  • The freeze blocks other changes to those 33 files until the bridge PRs land.

Additional Notes

Follow-up PRs, reviewed by their owners: telemetry's AppSec inputs (asm-python), and moving the serverless tests off the _threads alias. No release notes: internal refactors only.

@cit-pr-commenter-54b7da

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

.agents/skills/analyze-crash/SKILL.md                                   @DataDog/apm-python-guild
.github/CODEOWNERS                                                      @DataDog/apm-python-guild @DataDog/apm-core-python
.gitignore                                                              @DataDog/apm-python-guild
benchmarks/suitespec.yml                                                @DataDog/apm-core-python
ddtrace/__init__.py                                                     @DataDog/apm-python-guild
ddtrace/_error_attribution.py                                           (unowned)
ddtrace/_trace/processor/__init__.py                                    @DataDog/apm-sdk-capabilities
ddtrace/_trace/tracer.py                                                @DataDog/apm-sdk-capabilities
ddtrace/bootstrap/cloning.py                                            @DataDog/apm-python-guild @DataDog/apm-core-python
ddtrace/constants.py                                                    @DataDog/apm-python
ddtrace/contrib/internal/coverage/patch.py                              @DataDog/ci-app-libraries
ddtrace/contrib/internal/unittest/patch.py                              @DataDog/ci-app-libraries
ddtrace/internal/_encoding.pyi                                          @DataDog/apm-core-python
ddtrace/internal/_encoding.pyx                                          @DataDog/apm-core-python
ddtrace/internal/_runtime_id.py                                         @DataDog/apm-core-python
ddtrace/internal/_threads.py                                            @DataDog/apm-core-python
ddtrace/internal/atexit.py                                              @DataDog/apm-core-python
ddtrace/internal/ci_visibility/api/_base.py                             @DataDog/ci-app-libraries
ddtrace/internal/ci_visibility/api/_coverage_data.py                    @DataDog/ci-app-libraries
ddtrace/internal/ci_visibility/api/_module.py                           @DataDog/ci-app-libraries
ddtrace/internal/ci_visibility/encoder.py                               @DataDog/ci-app-libraries
ddtrace/internal/ci_visibility/utils.py                                 @DataDog/ci-app-libraries
ddtrace/internal/constants.py                                           @DataDog/apm-core-python
ddtrace/internal/core/crashtracking.py                                  @DataDog/profiling-python @DataDog/apm-core-python
ddtrace/internal/coverage/code.py                                       @DataDog/ci-app-libraries
ddtrace/internal/datastreams/processor.py                               @DataDog/data-streams-monitoring
ddtrace/internal/flare/flare.py                                         @DataDog/apm-core-python
ddtrace/internal/forksafe.py                                            @DataDog/apm-core-python
ddtrace/internal/logger.py                                              @DataDog/apm-core-python
ddtrace/internal/logger_setup.py                                        @DataDog/apm-core-python
ddtrace/internal/module.py                                              @DataDog/debugger-python @DataDog/apm-core-python
ddtrace/internal/native/__init__.py                                     @DataDog/apm-core-python
ddtrace/internal/native/_msgpack.pyi                                    @DataDog/apm-core-python
ddtrace/internal/native/_msgpack.pyx                                    @DataDog/apm-core-python
ddtrace/internal/native/_threads.cpp                                    @DataDog/apm-core-python
ddtrace/internal/native/_threads.pyi                                    @DataDog/apm-core-python
ddtrace/internal/native/pack.h                                          @DataDog/apm-core-python
ddtrace/internal/native/pack_template.h                                 @DataDog/apm-core-python
ddtrace/internal/native/sysdep.h                                        @DataDog/apm-core-python
ddtrace/internal/native_exceptions.py                                   @DataDog/apm-core-python
ddtrace/internal/native_runtime.py                                      @DataDog/apm-core-python
ddtrace/internal/packages.py                                            @DataDog/apm-core-python
ddtrace/internal/periodic.py                                            @DataDog/apm-core-python
ddtrace/internal/settings/_core.py                                      @DataDog/apm-core-python
ddtrace/internal/settings/_otel_remapper.py                             @DataDog/apm-sdk-capabilities
ddtrace/internal/settings/endpoint_config.py                            @DataDog/apm-core-python
ddtrace/internal/settings/env.py                                        @DataDog/apm-sdk-capabilities
ddtrace/internal/telemetry/__init__.py                                  @DataDog/apm-python
ddtrace/internal/telemetry/data.py                                      @DataDog/apm-python
ddtrace/internal/telemetry/dependency_tracker.py                        @DataDog/apm-python
ddtrace/internal/telemetry/writer.py                                    @DataDog/apm-python
ddtrace/internal/telemetry_inputs/__init__.py                           @DataDog/apm-core-python
ddtrace/internal/telemetry_inputs/library.py                            @DataDog/apm-core-python
ddtrace/internal/test_visibility/coverage_report_utils.py               @DataDog/ci-app-libraries
ddtrace/internal/threads.py                                             @DataDog/apm-core-python
ddtrace/internal/utils/formats.py                                       @DataDog/apm-core-python
ddtrace/internal/utils/http.py                                          @DataDog/apm-core-python
ddtrace/internal/utils/time.py                                          @DataDog/apm-core-python
ddtrace/internal/writer/writer.py                                       @DataDog/apm-core-python
ddtrace/profiling/_threading.pyx                                        @DataDog/profiling-python
ddtrace/testing/internal/api_client.py                                  @DataDog/ci-app-libraries
ddtrace/testing/internal/cached_file_provider.py                        @DataDog/ci-app-libraries
ddtrace/testing/internal/ci.py                                          @DataDog/ci-app-libraries
ddtrace/testing/internal/coverage_py/__init__.py                        @DataDog/ci-app-libraries
ddtrace/testing/internal/coverage_py/constants.py                       @DataDog/ci-app-libraries
ddtrace/testing/internal/coverage_py/data.py                            @DataDog/ci-app-libraries
ddtrace/testing/internal/coverage_py/lcov.py                            @DataDog/ci-app-libraries
ddtrace/testing/internal/coverage_py/patch.py                           @DataDog/ci-app-libraries
ddtrace/testing/internal/coverage_py/utils.py                           @DataDog/ci-app-libraries
ddtrace/testing/internal/dynamic_atr_retries.py                         @DataDog/ci-app-libraries
ddtrace/testing/internal/env_tags.py                                    @DataDog/ci-app-libraries
ddtrace/testing/internal/git.py                                         @DataDog/ci-app-libraries
ddtrace/testing/internal/http.py                                        @DataDog/ci-app-libraries
ddtrace/testing/internal/logs.py                                        @DataDog/ci-app-libraries
ddtrace/testing/internal/offline_mode.py                                @DataDog/ci-app-libraries
ddtrace/testing/internal/pytest/_discovery.py                           @DataDog/ci-app-libraries
ddtrace/testing/internal/pytest/_xdist.py                               @DataDog/ci-app-libraries
ddtrace/testing/internal/pytest/bdd.py                                  @DataDog/ci-app-libraries
ddtrace/testing/internal/pytest/plugin.py                               @DataDog/ci-app-libraries
ddtrace/testing/internal/pytest/utils.py                                @DataDog/ci-app-libraries
ddtrace/testing/internal/pytest/xdist.py                                @DataDog/ci-app-libraries
ddtrace/testing/internal/session_manager.py                             @DataDog/ci-app-libraries
ddtrace/testing/internal/settings_data.py                               @DataDog/ci-app-libraries
ddtrace/testing/internal/source_info.py                                 @DataDog/ci-app-libraries
ddtrace/testing/internal/telemetry.py                                   @DataDog/ci-app-libraries
ddtrace/testing/internal/tracer_api/__init__.py                         @DataDog/ci-app-libraries
ddtrace/testing/internal/tracer_api/context.py                          @DataDog/ci-app-libraries
ddtrace/testing/internal/tracer_api/coverage.py                         @DataDog/ci-app-libraries
ddtrace/testing/internal/writer.py                                      @DataDog/ci-app-libraries
docs/contributing-architecture.rst                                      @DataDog/apm-python-guild
frozen-paths.txt                                                        @DataDog/apm-core-python
mypy.ini                                                                @DataDog/apm-python-guild @DataDog/apm-core-python
scripts/check_native_python_imports.py                                  @DataDog/apm-python-guild
scripts/gen_gitlab_config.py                                            @DataDog/apm-python-guild
scripts/import-analysis/layers.json                                     @DataDog/apm-python-guild
scripts/lint                                                            @DataDog/apm-python-guild
scripts/supported_configurations.py                                     @DataDog/apm-sdk-capabilities
setup.py                                                                @DataDog/apm-python-guild
src/native/data_pipeline/trace_buffer.rs                                @DataDog/apm-core-python
src/native/lib.rs                                                       @DataDog/apm-core-python
src/native/span/wire.rs                                                 @DataDog/apm-core-python
tests/ci_visibility/test_utils.py                                       @DataDog/ci-app-libraries
tests/contrib/internal/coverage/test_utils.py                           @DataDog/apm-python-guild @DataDog/apm-idm-python
tests/coverage/test_coverage.py                                         @DataDog/ci-app-libraries
tests/internal/test_auto.py                                             @DataDog/apm-core-python
tests/internal/test_constants.py                                        @DataDog/apm-core-python
tests/internal/test_env.py                                              @DataDog/apm-sdk-capabilities
tests/internal/test_logger.py                                           @DataDog/apm-core-python
tests/internal/test_module_shared_loader.py                             @DataDog/apm-core-python
tests/internal/test_native.py                                           @DataDog/apm-core-python
tests/internal/test_periodic.py                                         @DataDog/apm-core-python
tests/internal/test_periodic_stress.py                                  @DataDog/apm-core-python
tests/internal/test_settings.py                                         @DataDog/apm-core-python
tests/internal/test_supported_configurations_script.py                  @DataDog/apm-core-python
tests/internal/test_threads.py                                          @DataDog/apm-core-python
tests/internal/test_utils.py                                            @DataDog/apm-core-python
tests/suitespec.yml                                                     @DataDog/apm-python-guild
tests/telemetry/test_telemetry_inputs.py                                @DataDog/apm-core-python @DataDog/apm-python
tests/telemetry/test_writer.py                                          @DataDog/apm-core-python @DataDog/apm-python
tests/testing/internal/coverage/conftest.py                             @DataDog/ci-app-libraries
tests/testing/internal/coverage/test_patch.py                           @DataDog/ci-app-libraries
tests/testing/internal/pytest/test_pytest_cov.py                        @DataDog/ci-app-libraries
tests/testing/internal/pytest/test_pytest_coverage_report_upload.py     @DataDog/ci-app-libraries
tests/testing/internal/test_source_info.py                              @DataDog/ci-app-libraries
tests/testing/internal/test_tracer_isolation.py                         @DataDog/ci-app-libraries
tests/tracer/test_native_trace_buffer.py                                @DataDog/apm-sdk-capabilities
tests/tracer/test_rand.py                                               @DataDog/apm-sdk-capabilities
tests/tracer/test_writer.py                                             @DataDog/apm-sdk-capabilities
tests/vendor/msgpack/test_buffer.py                                     @DataDog/apm-python-guild
tests/vendor/msgpack/test_case.py                                       @DataDog/apm-python-guild
tests/vendor/msgpack/test_except.py                                     @DataDog/apm-python-guild
tests/vendor/msgpack/test_limits.py                                     @DataDog/apm-python-guild
tests/vendor/msgpack/test_newspec.py                                    @DataDog/apm-python-guild
tests/vendor/msgpack/test_pack.py                                       @DataDog/apm-python-guild
tests/vendor/msgpack/test_read_size.py                                  @DataDog/apm-python-guild
tests/vendor/msgpack/test_seq.py                                        @DataDog/apm-python-guild
tests/vendor/msgpack/test_subtype.py                                    @DataDog/apm-python-guild
tests/vendor/msgpack/test_unpack.py                                     @DataDog/apm-python-guild

@cit-pr-commenter-54b7da

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

✅ Top-level modules now classified

1 top-level module(s) were classified in layers.json by this PR:

ddtrace._logger

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Nov 23, 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: 4cc1063 | Docs | View more details | Give us feedback!

@gnufede gnufede added the changelog/no-changelog A changelog entry is not required for this PR. label Nov 23, 2026
@pr-commenter

pr-commenter Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-11-26 12:14:34

Comparing candidate commit 4cc1063 in PR branch gnufede/package-split-prep with baseline commit b4924dd in branch main.

📊 Benchmarking dashboard

Found 3 performance improvements and 3 performance regressions! Performance is the same for 639 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:httppropagationextract-empty_headers

  • 🟩 execution_time [-99.545ns; -81.332ns] or [-12.889%; -10.531%]

scenario:httppropagationextract-wsgi_empty_headers

  • 🟩 execution_time [-108.556ns; -91.899ns] or [-13.881%; -11.751%]

scenario:httppropagationextract-wsgi_invalid_span_id_header

  • 🟩 execution_time [-93.248ns; -78.270ns] or [-12.050%; -10.114%]

scenario:packagesupdateimporteddependencies-import_one_cache

  • 🟥 execution_time [+763.711ns; +853.701ns] or [+10.501%; +11.739%]

scenario:packagesupdateimporteddependencies-import_one_stdlib_cache

  • 🟥 execution_time [+851.594ns; +943.922ns] or [+11.772%; +13.048%]

scenario:packagesupdateimporteddependencies-import_one_unknown_cache

  • 🟥 execution_time [+753.733ns; +838.037ns] or [+10.339%; +11.496%]

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 [-635.932ns; +758.147ns] or [-5.908%; +7.044%]

scenario:coreapiscenario-core_dispatch_1_listener

  • unstable execution_time [-39.779ns; +33.187ns] or [-6.143%; +5.125%]

scenario:coreapiscenario-core_dispatch_50_listeners

  • unstable execution_time [-1577.766ns; +2143.793ns] or [-7.831%; +10.640%]

scenario:coreapiscenario-core_dispatch_exception_listeners

  • unstable execution_time [-1837.685ns; +1624.087ns] or [-9.578%; +8.465%]

scenario:coreapiscenario-core_dispatch_listeners

  • unstable execution_time [-342.087ns; +393.388ns] or [-7.982%; +9.179%]

scenario:coreapiscenario-core_dispatch_no_args_listeners

  • unstable execution_time [-186.823ns; +254.456ns] or [-6.985%; +9.514%]

scenario:coreapiscenario-core_dispatch_with_results_1_listener

  • unstable execution_time [-85.985ns; +92.283ns] or [-6.408%; +6.877%]

scenario:coreapiscenario-core_dispatch_with_results_50_listeners

  • unstable execution_time [-5306.877ns; +3676.055ns] or [-10.738%; +7.438%]

scenario:coreapiscenario-core_dispatch_with_results_listeners

  • unstable execution_time [-1017.857ns; +802.544ns] or [-9.867%; +7.780%]

scenario:packagesupdateimporteddependencies-import_many_stdlib_cached

  • unstable execution_time [-27.355µs; +87.836µs] or [-4.694%; +15.071%]

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 and others added 15 commits November 23, 2026 16:08
…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>
Code extracted from ddtrace into sibling packages logs under
_ddtrace_internal.*, _ddtrace_coverage.* and _ddtrace_native.*, which
are not children of the "ddtrace" logger. They missed DD_TRACE_DEBUG,
DD_TRACE_LOG_LEVEL, the DD_TRACE_LOG_FILE handler and the per-product
_DD_<PRODUCT>_LOG_LEVEL settings.

configure_ddtrace_logger now configures every root in LOGGER_ROOTS the
same way, sharing one stream handler and one rotating file handler so
records are written once and the file is rotated consistently.
get_logger applies per-product levels to any "_ddtrace_<package>" name,
resolving it like "ddtrace.<package>", so logger.py does not have to
know the package list and can move into _ddtrace_internal unchanged.
Behaviour for existing ddtrace.* loggers is unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Resolving a package logger root by its own name changed the setting
for moved code, e.g. _ddtrace_coverage.* read _DD_COVERAGE_LOG_LEVEL
instead of the _DD_INTERNAL_COVERAGE_LOG_LEVEL it used inside ddtrace.

dd-trace-py now registers the path each package root had inside
ddtrace, so the settings keep their names. Registering re-levels any
package logger created earlier, so import order does not matter, and
an unregistered root still falls back to its own name.

Co-Authored-By: Claude Opus 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>
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 native TraceBuffer imported ddtrace.internal._encoding on first use
to get packb for meta_struct values. The extension is moving to a
standalone package that must not import any ddtrace module, so Python now
hands packb over through TraceBuffer._register_packb, like the forksafe
seed hook and the tracestate helpers.

The registration lives in ddtrace.internal.writer, which already imports
_encoding and is the only place that builds a TraceBuffer. It cannot live
in ddtrace.internal.native: _encoding imports the settings, which import
ddtrace.internal.native, so that would be an import cycle. Until a packer
is registered, write() keeps dropping each meta_struct entry with one
warning, because it must never raise into user code.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The native extension is moving to a standalone package that must not
import any ddtrace module. The previous reach-ins were removed by having
Python register the callables with native; this check keeps new ones from
coming back. It scans src/native for py.import/PyModule::import calls on
a ddtrace module, ignoring comments and plain string literals such as the
pyclass module attribute and event names.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…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>
Restarting a stopped StopWatch kept the previous stop time, so elapsed()
measured against it and returned a negative or frozen value instead of
the time since the restart.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A child setting (e.g. _DD_INTERNAL_COVERAGE_LOG_LEVEL) processed before
its parent created the parent node without a level, and the parent's
level was never applied. Lookup also returned the level of the last node
visited instead of the nearest configured ancestor, so a parent setting
was lost for loggers below an intermediate node with no setting of its
own. Always assign the level to the terminal node and track the nearest
configured level while descending.

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

Exception and stack text was appended to the message while the record
still held its %-style args, so a "%s" in an exception message made
record formatting fail and the log was lost. Build the message with
getMessage() and clear the args first.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A loader shared by several modules (e.g. a zipimporter) had get_code
wrapped once, capturing the first module and its transformers; the guard
against re-wrapping then kept later imports bound to them, so transforms
received the wrong module. Re-wrap the original get_code on every
exec_module so the wrapper is bound to the module being executed, which
still prevents wrappers from stacking on reloads.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@gnufede
gnufede force-pushed the gnufede/package-split-prep branch from 4339f64 to fd04a4e Compare November 23, 2026 15:25
gnufede and others added 2 commits November 24, 2026 07:23
…-prep

# Conflicts:
#	tests/internal/test_logger.py
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>
@gnufede
gnufede requested review from wconti27 and removed request for a team November 25, 2026 14:44

@datadog-datadog-prod-us1 datadog-datadog-prod-us1 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

Native runtime behavior remains unverified because compiled extensions were unavailable. The completed static review reported no actionable defects, with additional gaps in the setup.py base comparison and architecture analysis.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 034e3a7

@gnufede
gnufede requested a review from brettlangdon November 25, 2026 14:55
This module feeds integration names into telemetry's error attribution, so it is owned by the same team as ddtrace/internal/telemetry/.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
gnufede and others added 6 commits November 25, 2026 21:14
…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.
Modules that log through logging.getLogger(__name__) get a _ddtrace_*
logger name once they move into a package, outside the ddtrace logger,
so DD_TRACE_DEBUG, the ddtrace handlers and telemetry's error handler
stop seeing their records. The local end-to-end test of the final
layout hit this in the shared runtime and in test optimization.

Expose get_logger's name normalization as logger_name() and use it in
the stdlib-logging modules that move: the shared runtime ones and test
optimization. settings.env can't import the logger (the logger imports
it), so it spells its name out. In dd-trace-py every name is unchanged.

Refreezes logger.py, utils/formats.py and settings/env.py; the
ddtrace-internal port (DataDog/datadog-apm-python#77) re-syncs them.

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 and writers, so it moves next to them as native_exceptions.

Importing it no longer loads the Rust extension as a side effect;
ddtrace/__init__.py still loads it first for the fork reseed hook.

Co-Authored-By: Claude Opus 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 Opus 5.5 <noreply@anthropic.com>
The test optimization writer read ddtrace.version for the events'
library_version. It now reads the version registered with telemetry's
library inputs, which ddtrace/__init__.py sets to the same ddtrace
version, so events are unchanged. A standalone ddtrace-testing registers
its own name and version there, so its events report it without
importing ddtrace.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The settings package's env attribute is the config object, which
shadows the submodule, so attribute access found no logger.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
from ddtrace.internal.packages import get_version_for_package
from ddtrace.internal.settings._telemetry import config as telemetry_config
from ddtrace.internal.settings.appsec_telemetry import config as appsec_telemetry_config
from ddtrace.internal.telemetry_inputs.library import get_library

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

i have come across a few internal API changes like this one. I wonder if it would make sense to split them into dedicated PRs to make this easier to review

@P403n1x87 P403n1x87 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sorry for being a pain, but from a quick look it feels that there are a few independent chunks that can be split into their own bite-sized PRs 😅

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why can't this be a sub-module of ddtrace.internal.telemetry (e.g. ddtrace.internal.telemetry.inputs)?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this can probably be its own PR

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can't this be ddtrace.internal.(logger|logging).setup?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this seems like a fix that can go in its own PR

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Moving threads.cpp to native could also be its own PR

Comment thread ddtrace/__init__.py

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

adding more code here feels like it's going in the wrong direction whereby we'd love this to be essentially empty and side-effect-free. Can we try to figure out what really needs to stay here to avoid breaking the public API?

gh-worker-dd-mergequeue-cf854d Bot pushed a commit that referenced this pull request Nov 26, 2026
…ze moved module names (#22122)

## Description

Part of replacing #22018 with smaller PRs on `main`, one per module group. Addresses
#22018 (comment): the runtime setup of the `ddtrace` logger
lives next to the logger it configures (`ddtrace.internal.logger.setup`) instead of in a sibling `logger_setup`
module.

Prepares the logger to be extracted to `ddtrace-internal`
(DataDog/datadog-apm-python#77 ports `ddtrace/internal/logger/__init__.py` from this PR):

- `get_logger` normalizes `_ddtrace_<pkg>` module names to their former `ddtrace.*` path (and a public
  `logger_name()` does the same for stdlib-logging modules), so moved code stays under the `ddtrace` logger.
- `ddtrace/internal/logger.py` becomes `logger/__init__.py` and `ddtrace/_logger.py` becomes `logger/setup.py`
  (importing the logger does not import setup or telemetry; a test guards it). `DD_LOG_FORMAT` moves into
  `tests/internal/test_settings.py`, its only user. CODEOWNERS, suitespecs and the import-layer list follow.
- `logger/__init__.py` is added to `frozen-paths.txt`; `setup.py` moves later with telemetry and stays unfrozen.

## Testing

`tests/internal` (py3.12), the telemetry suite, `scripts/lint typing`, suitespec checks, and a fresh-interpreter
`import ddtrace`. New tests cover normalization, `logger_name` and per-product levels for `_ddtrace_*` names.

## Risks

None expected: in dd-trace-py no module uses a `_ddtrace_*` name yet, so normalization is a no-op.

## Additional notes

No release note (`changelog/no-changelog`): internal refactor. The two logger bug fixes found while porting are in their own PR, #22126, which should merge first; this PR's freeze hash is then updated.

🤖 Generated with [Claude Code](https://claude.com/claude-code)


Co-authored-by: federico.mon <federico.mon@datadoghq.com>
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.

4 participants