← Back to Pull requests

chore(iast): type logging wrappers #22178

Merged
florentinl merged 13 files (93 lines) on Nov 30, 2026 13:56 UTC
View on GitHub
florentinl florentinl commented on Nov 30, 2026 09:52 UTC
Author

<!-- dd-meta {"pullId":"8d486c82-c04a-4fd4-981f-85a6269d4eae","source":"chat","resourceId":"7444233a-2820-48cb-99ab-d6e11d7ce1d1","workflowId":"268d4d07-1acb-4469-a83e-d34cbe3387a5","codeChangeId":"268d4d07-1acb-4469-a83e-d34cbe3387a5","sourceType":"action_platform_workflows"} -->

Description

Workflow Automation • View in Workflow Automation

  • Add Python 3.9-compatible type annotations (Optional / Union, TypedDict + Unpack under TYPE_CHECKING) to all logging wrapper functions in ddtrace/appsec/_iast/_logs.py.

  • Remove the [mypy-ddtrace.appsec._iast._logs] exemption from mypy.ini, delete four now-obsolete # type: ignore[no-untyped-call] comments in ddtrace/appsec/_iast/_aiohttp.py, and update the line exception in scripts/check_constant_log_message.py (_logs.py:41 -> _logs.py:60).

  • Tighten iast_error(default_prefix: str = "iast::", ...) and fix all 19 call sites across 9 files (_langchain.py, code_injection.py, command_injection.py, header_injection.py, path_traversal.py, sql_injection.py, untrusted_serialization.py, weak_cipher.py, weak_hash.py) that were passing e positionally as default_prefix instead of exc=e.
  • Customer impact

    None under default settings — _set_iast_error_metric only emits telemetry logs when IAST debug mode is enabled.

    Testing

    Validated with scripts/lint typing, scripts/lint checks (including check_constant_log_message.py), scripts/lint type-comments-check --base-ref origin/main, and Python 3.9 IAST unit tests (tests/appsec/iast/test_telemetry.py and affected tests/appsec/iast/taint_sinks/ suites: 228 passed, 42 skipped).

    Risks

    Low — preserves all public/internal signatures while fixing the 19 iast_error(..., exc=e) error-reporting call sites.

    Additional Notes

    None.

    ---

    PR by Bits - View session in Datadog

    Comment @datadog to request changes

    Diff: 93 lines (+54 / -39) across 13 files Reviewer: christophe-papazian Review duration: 244m
    All Vouch review confidence checks passed
    Residual risk 0.10 = Change Risk (0.48) × (1 − Review Confidence (0.78)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 93 lines diff across 13 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.66 · 5 substantive comment(s)
    0.66
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    78%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.272
    Real PR Conversation Timeline
    9 items
    datadog-prod-us1-6[bot] datadog-prod-us1-6[bot] commented on Nov 30, 2026 09:52 UTC
    Bot

    View session in Datadog

    Bits Code status: ✅ Done

    Comment @datadog to request changes

    cit-pr-commenter-54b7da[bot] cit-pr-commenter-54b7da[bot] commented on Nov 30, 2026 09:53 UTC
    Bot

    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/appsec/_iast/_aiohttp.py                                        @DataDog/asm-python
    ddtrace/appsec/_iast/_langchain.py                                      @DataDog/asm-python
    ddtrace/appsec/_iast/_logs.py                                           @DataDog/asm-python
    ddtrace/appsec/_iast/taint_sinks/code_injection.py                      @DataDog/asm-python
    ddtrace/appsec/_iast/taint_sinks/command_injection.py                   @DataDog/asm-python
    ddtrace/appsec/_iast/taint_sinks/header_injection.py                    @DataDog/asm-python
    ddtrace/appsec/_iast/taint_sinks/path_traversal.py                      @DataDog/asm-python
    ddtrace/appsec/_iast/taint_sinks/sql_injection.py                       @DataDog/asm-python
    ddtrace/appsec/_iast/taint_sinks/untrusted_serialization.py             @DataDog/asm-python
    ddtrace/appsec/_iast/taint_sinks/weak_cipher.py                         @DataDog/asm-python
    ddtrace/appsec/_iast/taint_sinks/weak_hash.py                           @DataDog/asm-python
    mypy.ini                                                                @DataDog/apm-python-guild @DataDog/apm-core-python
    scripts/check_constant_log_message.py                                   @DataDog/apm-python-guild
    

    cit-pr-commenter-54b7da[bot] cit-pr-commenter-54b7da[bot] commented on Nov 30, 2026 09:53 UTC
    Bot

    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.

    <details><summary>Show existing violations (showing 5 of 22 highest severity)</summary>

    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)
    

    </details>

    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
    > 

    pr-commenter[bot] pr-commenter[bot] commented on Nov 30, 2026 10:21 UTC
    Bot

    Benchmarks

    Benchmark execution time: 2026-11-30 10:48:42

    Comparing candidate commit 33793ac3ccb80e6c2bd4ec736c88334af01fbe66 in PR branch dd/asm/hypertyper-iast-logging-20261130 with baseline commit 498511e8e1f87b07f4925fa85abb7cb85619e171 in branch main.

    📊 Benchmarking dashboard

    Found 0 performance improvements and 0 performance regressions! Performance is the same for 562 metrics, 10 unstable metrics, 1 flaky benchmarks without significant changes.

    <details>
    <summary><h3>Explanation</h3></summary>

    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.

    <details>
    <summary><h4>More details about the CI and significant changes</h4></summary>

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

    </details>

    </details>

    <details>
    <summary><h3>Unstable benchmarks</h3></summary>

    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 [-633.329ns; +815.150ns] or [-5.968%; +7.681%]
  • scenario:coreapiscenario-core_dispatch_1_listener

  • unstable execution_time [-37.293ns; +40.554ns] or [-5.863%; +6.376%]
  • scenario:coreapiscenario-core_dispatch_50_listeners

  • unstable execution_time [-1722.495ns; +2106.650ns] or [-8.705%; +10.647%]
  • scenario:coreapiscenario-core_dispatch_exception_listeners

  • unstable execution_time [-2223.360ns; +1477.861ns] or [-11.307%; +7.516%]
  • scenario:coreapiscenario-core_dispatch_listeners

  • unstable execution_time [-351.536ns; +406.091ns] or [-8.330%; +9.622%]
  • scenario:coreapiscenario-core_dispatch_no_args_listeners

  • unstable execution_time [-206.480ns; +246.881ns] or [-7.827%; +9.358%]
  • scenario:coreapiscenario-core_dispatch_with_results_1_listener

  • unstable execution_time [-95.345ns; +85.069ns] or [-6.912%; +6.167%]
  • scenario:coreapiscenario-core_dispatch_with_results_50_listeners

  • unstable execution_time [-5224.342ns; +4110.285ns] or [-10.631%; +8.364%]
  • scenario:coreapiscenario-core_dispatch_with_results_listeners

  • unstable execution_time [-1157.261ns; +734.088ns] or [-11.037%; +7.001%]
  • scenario:packagesupdateimporteddependencies-import_many_stdlib_cached

  • unstable execution_time [-48.752µs; +60.079µs] or [-8.440%; +10.401%]
  • </details>

    <details>
    <summary><h3>Known flaky benchmarks</h3></summary>

    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
  • </details>

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on Nov 30, 2026 10:25 UTC
    Bot

    <!-- codex-pull-request-review-summary -->
    <!-- codex-review-state:v1 {"code_review":{"commit_sha":"33793ac3ccb80e6c2bd4ec736c88334af01fbe66","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":"33793ac3ccb80e6c2bd4ec736c88334af01fbe66","has_any_findings":null,"has_unresolved_findings":null,"status":"completed"}} -->
    <!-- codex-security-review:v1 {"blockingSeverityThreshold":"P0","headSha":"33793ac3ccb80e6c2bd4ec736c88334af01fbe66","mergeGateEnabled":false,"pullRequestNumber":22178,"repository":"DataDog/dd-trace-py","status":"completed"} -->
    <details>
    <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary>

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

    | Review | Status | Commit | Review trigger |
    | --- | --- | --- | --- |
    | 📝 Code Review | ✅ Completed <relative-time datetime="2026-11-30T10:27:35.265554Z">2026-11-30T10:27:35.265554Z</relative-time> | 33793ac | Draft marked ready |
    | 🔒 Security Review | ✅ Completed <relative-time datetime="2026-11-30T10:33:03.180471Z">2026-11-30T10:33:03.180471Z</relative-time> | 33793ac | Draft marked ready |

    <details> <summary>ℹ️ About Codex in GitHub</summary>
    <br/>

    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.

    </details>

    </details>

    christophe-papazian christophe-papazian approved these changes on Nov 30, 2026 10:27 UTC
    Approved Reviewer

    Approved these changes.

    avara1986 avara1986 approved these changes on Nov 30, 2026 10:28 UTC
    Approved Reviewer

    Approved these changes.

    datadog-prod-us1-6[bot] datadog-prod-us1-6[bot] commented on Nov 30, 2026 10:30 UTC
    Reviewer

    <img src="https://img.shields.io/badge/BITS%20CODE%20REVIEW-PASS-1a7f37?labelColor=632CA6&style=for-the-badge&logo=data:image/svg%2Bxml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMjggMTI4Ij48cGF0aCBkPSJNNjMuNTUsNzQuMzJhNTUuMiw1NS4yLDAsMCwxLTEwLTguMzJjLS4zMS0uMjMtLjI2LTEuMjUtLjI2LTEuMjVBNTUuODEsNTUuODEsMCwwLDAsNjguOTQsNzMuMWExMi43NCwxMi43NCwwLDAsMCw5LjgxLS44MywyNSwyNSwwLDAsMCw3LjUzLTYuNjRsLjM0LjU5YTE0LjkzLDE0LjkzLDAsMCwxLTEuMjksMy4wNiw4LDgsMCwwLDAsMi4yNC44MWw2LS45M2ExOC4xMiwxOC4xMiwwLDAsMCwyLTE0LjMxYy0uOTMtMy01Ljc5LTkuMS02LjE0LTkuNDMtMS4yMi0xLjE3LjIxLTUuNy0yLjIxLTEwLjY1Qzg0LjY1LDI5LjU0LDc4LDI0LjA5LDc1LjA5LDIxLjcyYy44NS42Miw2LjEsMi43NCw4LjU1LDUuNjkuMjMtLjMuMzItMS44OS41My0yLjI5LTIuMS0yLjc2LTIuMjYtNy42Ni0yLjI2LTlBMTQuODcsMTQuODcsMCwwLDAsODAuNjksMTFhOC4xNiw4LjE2LDAsMCwxLDIuNjUs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MiwxLjYtLjE5LDMuODgtLjI5LDQuMzcsMCwxLC41MywxLDIuMTguMzEsMy43Mi0xLDIuMjItMi4zMyw0LjY3LTMuODgsNC44Ny0yLjUyLjM0LTQuOTEtMS03LjYzLTMuMDZBMi4yMywyLjIzLDAsMCwxLDc5LjI1LDU2LjYyWk01NS4zNCwzOS43NWM0LTIuNzMsOS4xNi0xLjY1LDguMy0uODMtMS42NSwxLjU2LjU0LDEuMS43OCw0YTUsNSwwLDAsMS0xLjEyLDRBMjUuNDksMjUuNDksMCwwLDAsNTguNyw0OGEyNiwyNiwwLDAsMC0yLjg1LDEuMTMsNy4zMiw3LjMyLDAsMCwxLS43My0uNTVBNS41Myw1LjUzLDAsMCwxLDU1LjM0LDM5Ljc1Wm02MC4xMSwyNy44Mi0zMi41MSw1LjlhMTYsMTYsMCwwLDEtMy43NSwzLjMzLDExLjc1LDExLjc1LDAsMCwxLTkuMjkuODUsMjAsMjAsMCwwLDEtMy43MS0xLjE5bC03Ljk1LDEuMSw0LjgzLDQwLjIsNTUuNy0xMFpNNjUuODgsMTEzLjkybC0uNDYtNC4zNyw5LjA5LTEzLjg4LDEwLjMzLDMsOC44OC0xNC44NCwxMC42NSw3LDguMS0xNywyLjg3LDMwLjkxWiIgZmlsbD0iI2ZmZiIvPjwvc3ZnPg%3D%3D" alt="Bits Code Review: PASS" height="36"/>

    <details>
    <summary>More details</summary>

    The corrected calls forward exceptions through exc while preserving the intended IAST message prefixes. The completed static review identified no reportable defects; human PR discussion raised no additional concerns.

    </details>
    Was this helpful? React 👍 or 👎

    <sub>Open Bits AI session</sub>

    <sub>🤖 Bits Code Review · Commit 33793ac</sub>

    <!-- autotest-meta model=gpt-6.1-sol engine=codex reasoning_effort=high verdict=PASS ddrs_bucket=unknown session_id=a1f27beb-5600-4118-b8db-302a8e62a5cc -->

    <!-- datadog-code-review reviewer-id=bad90057-5c12-4101-ad47-d91c9dff0f90 -->
    <!-- datadog-autotest:v1:prod -->
    <!-- datadog-autotest-delivery:v1:prod:3d5517522f576c9c5458979c43d8a99bbb959a68f822e32f818921dc5e5a83b8:bundle -->

    Assignees
    florentinl florentinl
    Labels
    risk: low confidence: 78.2% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.8% (MEDIUM) · Higher = larger blast radius
    47.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 78.2% · Lower = rushed or shallow review
    78.2%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 10.4% · Safe to merge
    10.4%