Skip to content

fix(logging): resolve per-product log levels independent of order and keep exception log text - #22126

Open
gnufede wants to merge 2 commits into
mainfrom
gnufede/logger-level-fixes
Open

gnufede wants to merge 2 commits into
mainfrom
gnufede/logger-level-fixes

Conversation

@gnufede

@gnufede gnufede commented Nov 26, 2026

Copy link
Copy Markdown
Member

Description

Two bugs in ddtrace.internal.logger found while preparing its extraction to ddtrace-internal. They're split out of #22122, the logger refactor, so they can be reviewed and backported on their own.

  • Per-product log levels resolve independently of order. A _DD_<PRODUCT>_LOG_LEVEL setting was lost when a more specific one (e.g. _DD_INTERNAL_COVERAGE_LOG_LEVEL before _DD_INTERNAL_LOG_LEVEL) was processed first, because the parent node already existed without a level. An intermediate node created only to reach a deeper setting also masked an ancestor's level on lookup.
  • Product log arguments are interpolated before the exception text is appended. The rate-limited product log filter appended the exception and stack text to the unformatted message and kept the arguments, so a % in the exception text broke the record's formatting.

Testing

New tests in tests/internal/test_logger.py: parent and child settings in either order, an intermediate node with no level, and a % in the exception message.

Risks

Low. Only _DD_*_LOG_LEVEL users who hit the first bug see different levels, and product log records keep the same text when they format correctly today.

Additional Notes

Release notes included for both fixes. Should merge before #22122, whose freeze hash for ddtrace/internal/logger is then updated.

🤖 Generated with Claude Code

gnufede and others added 2 commits November 26, 2026 15:55
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>
@cit-pr-commenter-54b7da

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/internal/logger.py                                              @DataDog/apm-core-python
releasenotes/notes/fix-product-log-exception-format-a7d40e5c1b2938f6.yaml  @DataDog/apm-python
releasenotes/notes/fix-product-log-level-order-3b1f7c2d9e4a6081.yaml    @DataDog/apm-python
tests/internal/test_logger.py                                           @DataDog/apm-core-python

@cit-pr-commenter-54b7da

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

@gnufede gnufede changed the title fix(internal): resolve per-product log levels independent of order and keep exception log text fix(logging): resolve per-product log levels independent of order and keep exception log text Nov 26, 2026
@gnufede
gnufede marked this pull request as ready for review November 26, 2026 15:00
@gnufede
gnufede requested review from a team as code owners November 26, 2026 15:00
@gnufede
gnufede requested review from P403n1x87 and removed request for a team November 26, 2026 15:00
@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:04:35.092134Z 06da6c7 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.

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

Static evidence supports order-independent parent/child log levels and preservation of percent signs in exception text. Runtime behavior was not exercised.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 06da6c7

@pr-commenter

pr-commenter Bot commented Nov 26, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-11-26 15:25:30

Comparing candidate commit 06da6c7 in PR branch gnufede/logger-level-fixes with baseline commit 386a387 in branch main.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 601 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 [-764.355ns; +710.492ns] or [-7.146%; +6.643%]

scenario:coreapiscenario-core_dispatch_1_listener

  • unstable execution_time [-37.841ns; +40.692ns] or [-5.909%; +6.354%]

scenario:coreapiscenario-core_dispatch_50_listeners

  • unstable execution_time [-1856.229ns; +1960.500ns] or [-9.280%; +9.802%]

scenario:coreapiscenario-core_dispatch_exception_listeners

  • unstable execution_time [-1796.479ns; +1827.695ns] or [-9.264%; +9.425%]

scenario:coreapiscenario-core_dispatch_listeners

  • unstable execution_time [-370.256ns; +383.751ns] or [-8.692%; +9.009%]

scenario:coreapiscenario-core_dispatch_no_args_listeners

  • unstable execution_time [-224.708ns; +227.867ns] or [-8.413%; +8.531%]

scenario:coreapiscenario-core_dispatch_with_results_1_listener

  • unstable execution_time [-86.246ns; +92.031ns] or [-6.283%; +6.705%]

scenario:coreapiscenario-core_dispatch_with_results_50_listeners

  • unstable execution_time [-4705.493ns; +4519.680ns] or [-9.718%; +9.334%]

scenario:coreapiscenario-core_dispatch_with_results_listeners

  • unstable execution_time [-936.941ns; +947.893ns] or [-9.174%; +9.281%]

scenario:packagesupdateimporteddependencies-import_many_stdlib_cached

  • unstable execution_time [-54.046µs; +58.004µs] or [-9.275%; +9.954%]

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

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant