Repository navigation
Conversation
Codeowners resolved asResolved from the full PR diff against |
Dependency direction analysis
|
🎉 All green!🧪 All tests passed 🔗 Commit SHA: 4cc1063 | Docs | View more details | Give us feedback! |
BenchmarksBenchmark execution time: 2026-11-26 12:14:34 Comparing candidate commit 4cc1063 in PR branch Found 3 performance improvements and 3 performance regressions! Performance is the same for 639 metrics, 10 unstable metrics, 1 flaky benchmarks without significant changes.
|
…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>
4339f64 to
fd04a4e
Compare
…-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>
There was a problem hiding this comment.
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.
🤖 Bits Code Review · Commit 034e3a7
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>
…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 |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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 😅
There was a problem hiding this comment.
why can't this be a sub-module of ddtrace.internal.telemetry (e.g. ddtrace.internal.telemetry.inputs)?
There was a problem hiding this comment.
this can probably be its own PR
There was a problem hiding this comment.
can't this be ddtrace.internal.(logger|logging).setup?
There was a problem hiding this comment.
this seems like a fix that can go in its own PR
There was a problem hiding this comment.
Moving threads.cpp to native could also be its own PR
There was a problem hiding this comment.
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?
…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>
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
ddtrace/internal/native/(Rust_native, plus_msgpackand_threads)ddtrace-nativeddtrace/internal/ddtrace-internalddtrace-native, neverddtraceddtrace/internal/coverage/ddtrace-coverageddtrace/testing/ddtrace-testing(later)What changes
envgets the supported-configurations registry (with aliases and sensitive names) fromddtrace/__init__.pyinstead of importing it.get_loggerlogs package code under its formerddtrace.*name, so log names, handlers and_DD_<PRODUCT>_LOG_LEVELare unchanged. This also fixes order-dependent level resolution and%arguments being formatted after the exception text.logginguse the same normalization aslogging.getLogger(logger_name(__name__)).settings.envcan't import the logger, so it spells its name out.ddtrace/internal/logger_setup.py._encodingintonative/_msgpack, and_threadsmoves intonative/._msgpacknext to it, so it no longer importsddtraceand_register_packbis gone.native/__init__.pynow only re-exports. The fork reseed hook is registered inddtrace/__init__.py, and the Python helpernative/exceptions.pymoves out tonative_exceptions.py.scripts/lint native-import-checkenforces this.ddtrace.internal._threadsstays as a temporary alias for now.ddtrace/internal/telemetry_inputs/instead of importing them. This also fixes error attribution, which would have missed_ddtrace_*paths.packages.pyfinds itsthird-party.tar.gzdata from its own package instead of the hardcodedddtrace.internal.tracer_api.ci_visibilityhelpers it used, and the coverage.py logic, move intoddtrace.testing;contrib.internal.coveragestays as a thin integration.library_versionfrom the version registered with telemetry, which is ddtrace's, so they're unchanged.sysconfig.internal/constants, andddtrace.constantsre-exports them unchanged.cleanup_loaded_modules()keeps_ddtrace_*modules, so bridged modules aren't imported twice.frozen-paths.txtfreezes the 33 files ported in this wave: 15 toddtrace-internal0.4.0 (DataDog/datadog-apm-python#77) and 18 toddtrace-coverage(DataDog/datadog-apm-python#82). Each package's bridge PR removes its entries.Testing
_msgpackand_threadsbinaries, loaded without ddtrace;import ddtrace,ddtrace.autoandddtrace-run;ddtrace.constantsnamespace.ddtrace-internal(with the shared runtime),ddtrace-coverage,ddtrace-nativeand a prototypeddtrace-testing. On Python 3.13 every suite matched the base branch by failing test ID, and pytest ran with the plugin withoutddtraceinstalled. The last four changes (logger names,native_exceptions, thepackages.pydata lookup, the test-event version) came out of it.native-import-check,supported-config-check, layers and suitespec checks pass.packband the encoders benchmark within noise.Risks
ddtrace/__init__.pynow registers the configuration registry, the reseed hook and the telemetry inputs before anything else, soforksafe,nativeandutils.versionload earlier.get_loggerorlogger_name. A plainlogging.getLogger(__name__)isn't normalized.Additional Notes
Follow-up PRs, reviewed by their owners: telemetry's AppSec inputs (asm-python), and moving the serverless tests off the
_threadsalias. No release notes: internal refactors only.