← Back to Pull requests

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

Closed
unknown closed this pull request without merging on Nov 27, 2026 12:04 UTC
View on GitHub
unknown unknown commented on Nov 23, 2026 12:16 UTC
Author

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.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: gnufede Review duration: 5748m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #22018"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%