Skip to content

fix(internal): format logged exceptions on Python 3.9 - #22026

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
mainfrom
gnufede/fix-logger-exc-info-py39
Nov 23, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
mainfrom
gnufede/fix-logger-exc-info-py39

Conversation

@gnufede

@gnufede gnufede commented Nov 23, 2026

Copy link
Copy Markdown
Member

Description

On Python 3.9, a product log that carries exception info (log.error(..., exc_info=True, extra={"product": ...})) raised TypeError inside ddtrace's logging filter, so the log call itself failed.

ddtrace/internal/logger.py called traceback.format_exception(record.exc_info[1], limit=...). That single-exception signature only exists from Python 3.10. This change calls traceback.format_exception(*record.exc_info, limit=...), which works on every supported Python.

Found while porting ddtrace/internal/logger.py to the ddtrace-internal package (DataDog/datadog-apm-python#77). It's split out as its own PR so it can be backported.

Testing

  • New test_product_log_formats_exc_info in tests/internal/test_logger.py.
  • On Python 3.9 the test fails without the fix and passes with it.
  • tests/internal/test_logger.py passes on 3.9 and 3.12 (12 passed).

Risks

None. The output is unchanged on 3.10+.

Additional Notes

Release note included.

traceback.format_exception(exc) with a single argument only exists in
Python 3.10+, so product logs carrying exc_info raised a TypeError inside
the logging filter on 3.9, which dd-trace-py still supports. Pass the
(type, value, traceback) triple instead, which works on every version.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@gnufede
gnufede requested review from a team as code owners November 23, 2026 15:07
@gnufede
gnufede requested review from P403n1x87 and removed request for a team November 23, 2026 15:07
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 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-23T15:08:31.645467Z aaf8b03 PR opened
ℹ️ 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.

@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-exc-info-py39-5e1c0a7d93b24f68.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.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

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

Passing the complete exception tuple fixes the Python 3.9 signature mismatch while remaining compatible with later Python versions. The added regression test exercises the affected product-logging path.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit aaf8b03

@datadog-prod-us1-4

datadog-prod-us1-4 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: aaf8b03 | Docs | View more details | Give us feedback!

@pr-commenter

pr-commenter Bot commented Nov 23, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-11-23 15:38:27

Comparing candidate commit aaf8b03 in PR branch gnufede/fix-logger-exc-info-py39 with baseline commit 0a79eb4 in branch main.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 644 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 [-576.190ns; +825.947ns] or [-5.389%; +7.724%]

scenario:coreapiscenario-core_dispatch_1_listener

  • unstable execution_time [-33.169ns; +41.190ns] or [-5.193%; +6.449%]

scenario:coreapiscenario-core_dispatch_50_listeners

  • unstable execution_time [-1470.767ns; +2189.867ns] or [-7.420%; +11.048%]

scenario:coreapiscenario-core_dispatch_exception_listeners

  • unstable execution_time [-1839.223ns; +1716.948ns] or [-9.436%; +8.809%]

scenario:coreapiscenario-core_dispatch_listeners

  • unstable execution_time [-235.418ns; +495.228ns] or [-5.583%; +11.744%]

scenario:coreapiscenario-core_dispatch_no_args_listeners

  • unstable execution_time [-87.552ns; +352.620ns] or [-3.323%; +13.383%]

scenario:coreapiscenario-core_dispatch_with_results_1_listener

  • unstable execution_time [-97.704ns; +77.463ns] or [-6.987%; +5.540%]

scenario:coreapiscenario-core_dispatch_with_results_50_listeners

  • unstable execution_time [-4426.986ns; +4536.470ns] or [-9.084%; +9.309%]

scenario:coreapiscenario-core_dispatch_with_results_listeners

  • unstable execution_time [-789.205ns; +1061.103ns] or [-7.636%; +10.267%]

scenario:packagesupdateimporteddependencies-import_many_stdlib_cached

  • unstable execution_time [-57.376µs; +54.574µs] or [-9.771%; +9.294%]

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
gh-worker-dd-mergequeue-cf854d Bot merged commit 99dfcab into main Nov 23, 2026
884 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the gnufede/fix-logger-exc-info-py39 branch November 23, 2026 17:43
gnufede added a commit that referenced this pull request Nov 24, 2026
main's fixes for logged exceptions on Python 3.9 (#22026) and run_module
hooks (#22027) changed logger.py and module.py, so their frozen hashes
must match the merged content.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.

2 participants