Skip to content

chore: handle potential after-import exceptions - #19786

Open
P403n1x87 wants to merge 1 commit into
mainfrom
chore/handle-after-import-exceptions
Open

chore: handle potential after-import exceptions#19786
P403n1x87 wants to merge 1 commit into
mainfrom
chore/handle-after-import-exceptions

Conversation

@P403n1x87

Copy link
Copy Markdown
Collaborator

Description

We handle potential exceptions raised during the execution of the after-import module watchdog hook.

@P403n1x87
P403n1x87 requested review from a team as code owners August 20, 2026 11:18
@P403n1x87 P403n1x87 added the changelog/no-changelog A changelog entry is not required for this PR. label Aug 20, 2026
@P403n1x87
P403n1x87 requested a review from juanjux August 20, 2026 11:18
@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/module.py                                              @DataDog/debugger-python @DataDog/apm-core-python
tests/internal/test_module.py                                           @DataDog/debugger-python @DataDog/apm-core-python

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Circular import analysis

⚠️ Existing circular imports

There are 3 circular imports that already exist on the base branch and have not been changed by this PR.

ddtrace.llmobs -> ddtrace.llmobs._evaluators -> ddtrace.llmobs._evaluators.format -> ddtrace.llmobs._experiment -> ddtrace.llmobs
ddtrace.errortracking._handled_exceptions.bytecode_injector -> ddtrace.errortracking._handled_exceptions.callbacks -> ddtrace.errortracking._handled_exceptions.collector -> ddtrace.errortracking._handled_exceptions.bytecode_reporting -> ddtrace.errortracking._handled_exceptions.bytecode_injector
ddtrace.appsec._asm_request_context -> ddtrace.appsec._iast._iast_request_context_base -> ddtrace.appsec._iast._iast_env -> ddtrace.appsec._iast.reporter -> ddtrace.appsec._exploit_prevention.stack_traces -> ddtrace.appsec._asm_request_context

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Aug 20, 2026

Copy link
Copy Markdown

Dependency direction analysis

⚠️ Existing dependency direction violations

There are 252 dependency direction violations that already exist on the base branch and have not been changed by this PR.

Show existing violations (showing 5 of 252 highest severity)
ddtrace.internal.tracemethods -×-> ddtrace.trace  (internal-core -> product:tracing, score=135)
ddtrace.llmobs._integrations.langgraph -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=133)
ddtrace.internal.opentelemetry.trace -×-> ddtrace.trace  (product:opentelemetry -> product:tracing, score=133)
ddtrace.llmobs._integrations.anthropic -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=133)
ddtrace.internal.ci_visibility.api._base -×-> ddtrace.trace  (product:ci_visibility -> product:tracing, score=133)

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

@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: 5d85499c03

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/internal/test_module.py Outdated
Comment on lines +361 to +362
@pytest.mark.subprocess
def test_module_watchdog_after_import_hook_isolation():

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Allow the expected stderr from the failing hook

This subprocess test installs Failing.after_import, which always raises, and the changed loader logs that exception with log.exception; under the default ddtrace logger this writes a traceback to stderr. The subprocess harness defaults err to "" and fails when stderr is non-empty, so this regression test will fail in the internal suite unless the marker disables/checks stderr output or disables the stream handler.

Useful? React with 👍 / 👎.

@datadog-datadog-us1-prod

datadog-datadog-us1-prod Bot commented Aug 20, 2026

Copy link
Copy Markdown

Pipelines  Tests

Unblock PR with BitsAI

⚠️ Warnings

🚦 9 Pipeline jobs failed

DataDog/apm-reliability/dd-trace-py | build linux serverless: [amd64, cp315-cp315, v126532274-233089d-musllinux_1_2_x86_64, 1] — 🔧 Needs a code fix, caused by this PR

View in Datadog · View in GitLab

DataDog/apm-reliability/dd-trace-py | build linux serverless: [arm64, cp315-cp315, v113741357-d2b8243-manylinux2014_aarch64, 1] — 🔧 Needs a code fix, caused by this PR

View in Datadog · View in GitLab

DataDog/apm-reliability/dd-trace-py | build linux: [amd64, cp315-cp315, v126532274-233089d-musllinux_1_2_x86_64] — 🔧 Needs a code fix, caused by this PR

View in Datadog · View in GitLab

View all 9 failed jobs.

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 202b0f4 | Docs | View more details | Give us feedback!

We handle potential exceptions raised during the execution of the
after-import module watchdog hook.
@P403n1x87
P403n1x87 force-pushed the chore/handle-after-import-exceptions branch from 5d85499 to 202b0f4 Compare August 20, 2026 11:32
@pr-commenter

pr-commenter Bot commented Aug 20, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-08-20 12:01:30

Comparing candidate commit 202b0f4 in PR branch chore/handle-after-import-exceptions with baseline commit 9e9c838 in branch main.

📊 Benchmarking dashboard

Found 0 performance improvements and 10 performance regressions! Performance is the same for 606 metrics, 10 unstable metrics.

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 ----------------------------------'

scenario:httppropagationextract-wsgi_valid_headers_all

  • 🟥 execution_time [+443.444ns; +493.730ns] or [+8.120%; +9.040%]

scenario:httppropagationinject-ids_only

  • 🟥 execution_time [+1.525µs; +1.665µs] or [+7.933%; +8.661%]

scenario:iastaspects-casefold_noaspect

  • 🟥 execution_time [+47.900µs; +56.802µs] or [+19.773%; +23.448%]

scenario:iastaspects-swapcase_aspect

  • 🟥 execution_time [+32.636µs; +41.741µs] or [+11.624%; +14.868%]

scenario:iastaspectsospath-ospathbasename_aspect

  • 🟥 execution_time [+104.511µs; +113.269µs] or [+24.958%; +27.050%]

scenario:iastaspectssplit-rsplit_aspect

  • 🟥 execution_time [+18.120µs; +22.639µs] or [+12.410%; +15.505%]

scenario:samplingrules-high_match

  • 🟥 execution_time [+11.288µs; +13.558µs] or [+7.180%; +8.625%]

scenario:span-start

  • 🟥 execution_time [+1.353ms; +1.543ms] or [+9.079%; +10.353%]

scenario:telemetryaddmetric-1-count-metric-1-times

  • 🟥 execution_time [+522.048ns; +562.892ns] or [+19.585%; +21.117%]

scenario:tracer-small

  • 🟥 execution_time [+29.378µs; +31.402µs] or [+8.805%; +9.411%]

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 [-713.053ns; +751.305ns] or [-6.484%; +6.832%]

scenario:coreapiscenario-core_dispatch_1_listener

  • unstable execution_time [-33.579ns; +32.724ns] or [-5.510%; +5.370%]

scenario:coreapiscenario-core_dispatch_50_listeners

  • unstable execution_time [-1787.291ns; +1515.889ns] or [-10.457%; +8.869%]

scenario:coreapiscenario-core_dispatch_exception_listeners

  • unstable execution_time [-1350.260ns; +1132.358ns] or [-10.337%; +8.669%]

scenario:coreapiscenario-core_dispatch_listeners

  • unstable execution_time [-319.531ns; +330.619ns] or [-8.706%; +9.008%]

scenario:coreapiscenario-core_dispatch_no_args_listeners

  • unstable execution_time [-249.285ns; +263.694ns] or [-8.533%; +9.026%]

scenario:coreapiscenario-core_dispatch_with_results_1_listener

  • unstable execution_time [-75.915ns; +68.776ns] or [-6.639%; +6.014%]

scenario:coreapiscenario-core_dispatch_with_results_50_listeners

  • unstable execution_time [-4032.751ns; +3932.398ns] or [-9.882%; +9.636%]

scenario:coreapiscenario-core_dispatch_with_results_listeners

  • unstable execution_time [-790.158ns; +761.959ns] or [-9.704%; +9.358%]

scenario:packagesupdateimporteddependencies-import_many_stdlib_cached

  • unstable execution_time [-58.017µs; +64.171µs] or [-9.024%; +9.982%]

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.

1 participant