Skip to content

refactor(logging): make ddtrace.internal.logger a package and normalize moved module names - #22122

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 3 commits into
mainfrom
gnufede/package-split-logger-package
Nov 26, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 3 commits into
mainfrom
gnufede/package-split-logger-package

Conversation

@gnufede

@gnufede gnufede commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

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

@cit-pr-commenter-54b7da

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

@cit-pr-commenter-54b7da

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

.github/CODEOWNERS                                                      @DataDog/apm-python-guild @DataDog/apm-core-python
benchmarks/suitespec.yml                                                @DataDog/apm-core-python
ddtrace/__init__.py                                                     @DataDog/apm-python-guild
ddtrace/internal/flare/flare.py                                         @DataDog/apm-core-python
ddtrace/internal/logger/__init__.py                                     @DataDog/apm-core-python
ddtrace/internal/logger/setup.py                                        @DataDog/apm-python-guild
frozen-paths.txt                                                        @DataDog/apm-core-python
scripts/import-analysis/layers.json                                     @DataDog/apm-python-guild
tests/internal/test_logger.py                                           @DataDog/apm-core-python
tests/internal/test_settings.py                                         @DataDog/apm-core-python
tests/suitespec.yml                                                     @DataDog/apm-python-guild

@gnufede
gnufede force-pushed the gnufede/package-split-logger-package branch from 7270701 to defaeb4 Compare November 26, 2026 14:46
@gnufede gnufede changed the title refactor(internal): make ddtrace.internal.logger a package with a setup module chore(logging): make ddtrace.internal.logger a package and normalize moved module names Nov 26, 2026
@gnufede gnufede added the changelog/no-changelog A changelog entry is not required for this PR. label Nov 26, 2026
@gnufede
gnufede changed the base branch from gnufede/package-split-prep to main November 26, 2026 14:47
@pr-commenter

pr-commenter Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-11-26 15:24:22

Comparing candidate commit eddd479 in PR branch gnufede/package-split-logger-package with baseline commit 386a387 in branch main.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 618 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 ----------------------------------'

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 [-742.877ns; +731.521ns] or [-6.963%; +6.856%]

scenario:coreapiscenario-core_dispatch_1_listener

  • unstable execution_time [-40.475ns; +38.578ns] or [-6.333%; +6.036%]

scenario:coreapiscenario-core_dispatch_50_listeners

  • unstable execution_time [-1886.708ns; +1935.210ns] or [-9.443%; +9.685%]

scenario:coreapiscenario-core_dispatch_exception_listeners

  • unstable execution_time [-1892.496ns; +1768.784ns] or [-9.779%; +9.140%]

scenario:coreapiscenario-core_dispatch_listeners

  • unstable execution_time [-388.351ns; +366.164ns] or [-9.116%; +8.596%]

scenario:coreapiscenario-core_dispatch_no_args_listeners

  • unstable execution_time [-221.265ns; +234.216ns] or [-8.317%; +8.804%]

scenario:coreapiscenario-core_dispatch_with_results_1_listener

  • unstable execution_time [-94.424ns; +88.036ns] or [-6.986%; +6.513%]

scenario:coreapiscenario-core_dispatch_with_results_50_listeners

  • unstable execution_time [-4923.128ns; +4375.620ns] or [-10.133%; +9.006%]

scenario:coreapiscenario-core_dispatch_with_results_listeners

  • unstable execution_time [-922.341ns; +969.778ns] or [-9.041%; +9.506%]

scenario:packagesupdateimporteddependencies-import_many_stdlib_cached

  • unstable execution_time [-55626.956ns; +54990.427ns] or [-9.658%; +9.548%]

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 3 commits November 26, 2026 15:55
Code moved into packages gets module names such as _ddtrace_internal,
_ddtrace_coverage and _ddtrace_native. get_logger now normalizes those
names to the path they had inside ddtrace instead, e.g.
_ddtrace_coverage.code -> ddtrace.internal.coverage.code, so moved code
stays under the ddtrace logger: one root for handlers and levels,
_DD_<PRODUCT>_LOG_LEVEL keeps working unchanged, and the tracer flare and
debug logging need no change.

The package table lives in logger.py, which moves to ddtrace-internal
as-is, so it adds no import. An unlisted _ddtrace_<x> root maps to
ddtrace.<x>. Modules that log through stdlib logging instead of
get_logger use the public logger_name() to get the same name.

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

The logger moves to ddtrace-internal, but the runtime setup of the ddtrace
logger (handlers, levels, native backend) imports telemetry and stays in
dd-trace-py for now. Keep them side by side: logger.py becomes
logger/__init__.py and _logger.py becomes logger/setup.py, so the logger
is a self-contained package that can later be bridged to ddtrace-internal
while setup moves on its own schedule. Importing ddtrace.internal.logger
does not import setup or telemetry; a test guards that.

DD_LOG_FORMAT moves into tests/internal/test_settings.py, its only user.
CODEOWNERS, the suitespecs and the import-layer top-level list follow the
move.

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

The logger package module moves to ddtrace-internal
(DataDog/datadog-apm-python#77). Freeze it so it cannot drift while the
port is in flight; the PR that replaces it with a bridge removes the
entry. logger/setup.py moves later together with telemetry and stays
unfrozen.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@gnufede
gnufede force-pushed the gnufede/package-split-logger-package branch from defaeb4 to eddd479 Compare November 26, 2026 14:57
@gnufede gnufede changed the title chore(logging): make ddtrace.internal.logger a package and normalize moved module names refactor(logging): make ddtrace.internal.logger a package and normalize moved module names Nov 26, 2026
@datadog-prod-us1-5

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

@gnufede
gnufede marked this pull request as ready for review November 26, 2026 15:51
@gnufede
gnufede requested review from a team as code owners November 26, 2026 15:51
@gnufede
gnufede requested review from emmettbutler and yaronguro-datadog and removed request for a team November 26, 2026 15:51
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T15:55:18.464642Z eddd479 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eddd4791a7

ℹ️ 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".

Comment thread ddtrace/internal/logger/__init__.py Resolved

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

Existing ddtrace.* names retain their logger identities, while ddtrace* names map into the ddtrace hierarchy. Runtime import and logging behavior were not exercised during this static review.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit eddd479

@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit 257b955 into main Nov 26, 2026
892 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the gnufede/package-split-logger-package branch November 26, 2026 16:28
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.

2 participants