Skip to content

chore(coverage): add coverage import data opt-out - #21405

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 4 commits into
mainfrom
gnufede/itr-coverage-opt-out-import-data
Nov 24, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 4 commits into
mainfrom
gnufede/itr-coverage-opt-out-import-data

Conversation

@gnufede

@gnufede gnufede commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds private _DD_COVERAGE_INCLUDE_IMPORT_DATA (default true). Setting it to false stops per-test coverage payloads from being augmented with the import-time coverage of each test's transitive import closure — a fixed per-test cost that scales with repo size rather than test work.

  • Reporting only: import-time collection keeps running; re-enabling restores full data immediately.
  • A warning is logged once per process when the opt-out is active.
  • Private on purpose: opting out degrades test skipping correctness — changes to code a test imports but never executes may select zero tests. Stays undocumented until we have a correctness story (the import-only coverage mode).

Validation

  • tests/coverage/test_import_data_opt_out.py (new): parametrized over _DD_COVERAGE_FILE_LEVEL × the new variable, on py3.10 and py3.12
  • Full tests/coverage and tests/ci_visibility suites pass; lint clean

Notes

  • No release note (private variable, changelog/no-changelog).
  • The strategic fix remains the import-only coverage mode; this is a stopgap for per-test overhead on large repos.

Per-test coverage reports are augmented with the import-time coverage
of the transitive import closure of the files each test touches. On
large first-party codebases this is a fixed per-test cost that scales
with repo size rather than test work, dominating per-test duration.

Add _DD_COVERAGE_INCLUDE_IMPORT_DATA (default true) to opt out of that
augmentation in both the instrumented-mode context expansion and the
CI Visibility per-test report path. Import-time coverage collection
itself keeps running: only per-test reporting skips the augmentation.

The variable is private on purpose: opting out degrades test skipping
correctness, since changes to code that a test imports but does not
execute may no longer select that test. A warning is logged once when
the opt-out is active.
@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/ci_visibility/coverage.py                              @DataDog/ci-app-libraries
ddtrace/internal/coverage/instrumented_mode.py                          @DataDog/ci-app-libraries
ddtrace/internal/coverage/util.py                                       @DataDog/ci-app-libraries
ddtrace/internal/settings/_supported_configurations.py                  @DataDog/apm-python
supported-configurations.json                                           @DataDog/apm-python
tests/coverage/test_import_data_opt_out.py                              @DataDog/ci-app-libraries

@cit-pr-commenter-54b7da

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

@datadog-prod-us1-4

datadog-prod-us1-4 Bot commented Oct 30, 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: 996fc21 | Docs | View more details | Give us feedback!

@pr-commenter

pr-commenter Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-11-24 15:32:29

Comparing candidate commit 996fc21 in PR branch gnufede/itr-coverage-opt-out-import-data with baseline commit 85d17e0 in branch main.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 635 metrics, 11 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 [-517.302ns; +886.065ns] or [-4.859%; +8.323%]

scenario:coreapiscenario-core_dispatch_1_listener

  • unstable execution_time [-34.138ns; +40.107ns] or [-5.319%; +6.249%]

scenario:coreapiscenario-core_dispatch_50_listeners

  • unstable execution_time [-1549.487ns; +2117.166ns] or [-7.803%; +10.662%]

scenario:coreapiscenario-core_dispatch_exception_listeners

  • unstable execution_time [-1697.189ns; +1792.330ns] or [-8.787%; +9.280%]

scenario:coreapiscenario-core_dispatch_listeners

  • unstable execution_time [-246.546ns; +484.926ns] or [-5.839%; +11.485%]

scenario:coreapiscenario-core_dispatch_no_args_listeners

  • unstable execution_time [-89.600ns; +352.812ns] or [-3.404%; +13.406%]

scenario:coreapiscenario-core_dispatch_with_results_1_listener

  • unstable execution_time [-96.031ns; +78.712ns] or [-6.982%; +5.723%]

scenario:coreapiscenario-core_dispatch_with_results_50_listeners

  • unstable execution_time [-4367.915ns; +4637.075ns] or [-8.940%; +9.491%]

scenario:coreapiscenario-core_dispatch_with_results_listeners

  • unstable execution_time [-932.474ns; +875.837ns] or [-9.006%; +8.459%]

scenario:flasksqli-iast-enabled

  • unstable execution_time [-72.311µs; +192.698µs] or [-3.908%; +10.415%]

scenario:packagesupdateimporteddependencies-import_many_stdlib_cached

  • unstable execution_time [-52.199µs; +59.472µs] or [-8.952%; +10.199%]

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 gnufede added the changelog/no-changelog A changelog entry is not required for this PR. label Oct 30, 2026
@gnufede gnufede changed the title feat(coverage): add private _DD_COVERAGE_INCLUDE_IMPORT_DATA opt-out chore(coverage): add coverage import data opt-out Oct 30, 2026
@gnufede
gnufede marked this pull request as ready for review October 30, 2026 17:31
@gnufede
gnufede requested review from a team as code owners October 30, 2026 17:31
@gnufede
gnufede requested review from r1viollet and removed request for a team October 30, 2026 17:31
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 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-24T15:00:44.273586Z 996fc21 New commits
ℹ️ 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: cb270f8d80

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

@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

The opt-out preserves import-time collection and suppresses its addition to reported coverage. Runtime behavior remains unverified because the reviewer’s test attempt stopped during native dependency compilation.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit cb270f8

The once-per-process opt-out warning only fired from
InstrumentedCoverage.expand_context_lines/files, which are reached via
CollectInContext.get_covered_lines()/get_covered_file_paths(). The
unittest internal-coverage reporter (_DD_USE_INTERNAL_COVERAGE=true)
reports through ModuleCodeCollector.report_seen_lines instead and
bypassed the expansion hooks, so opting out of import data silently
dropped it from per-test coverage reports without the warning the
opt-out promises.

Move the warning to a shared once-per-process helper in coverage.util
and call it from both the expansion hooks and the internal-coverage
reporting path, so whichever path reports first logs it exactly once.

Addresses the Codex review finding on PR #21405.

@brettlangdon brettlangdon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

apm-python, lgtm

gnufede added a commit that referenced this pull request Nov 24, 2026
## Description

**Stacked on #22018** (base `gnufede/package-split-prep`). This freezes
every file of the package split's first wave, so nothing can drift
between the port and the bridge. It replaces #21967, #21973 and #21990.

33 files are frozen, with hashes of their content after #22018:

- **Moving whole to `ddtrace-internal`**
(DataDog/datadog-apm-python#77): `utils/cache.py`, `utils/paths.py`,
`utils/obfuscation.py`, `utils/time.py`, `compat.py`, `assembly.py`,
`logger.py`, `settings/__init__.py`, `settings/env.py`, `module.py`,
`bytecode_injection/core.py`.
- **Partially moving, frozen whole** so the ported symbols stay
identical:
- `utils/__init__.py` (`get_argument_value`, `set_argument_value`,
`ArgumentError`);
  - `utils/formats.py` (`asbool`);
  - `utils/inspection.py` (`resolved_code_origin`);
  - `bytecode_injection/__init__.py` (`HookType`, `INJECTION_ASSEMBLY`).
- **Moving to `ddtrace-coverage`** (DataDog/datadog-apm-python#82): all
18 files under `ddtrace/internal/coverage/`.

`src/native` is not frozen here. The native switch is a separate step
that waits on the profiling team's agreement on the profiling FFI
approach.

The bridge PR, landing after `ddtrace-internal` 0.4.0 and
`ddtrace-coverage` 0.1.0 are released, replaces these modules with
re-exports and removes these entries in the same PR.

## Testing

Only `frozen-paths.txt` changes. All 33 hashes were checked against the
committed file contents (the same comparison `freeze-check.yml` makes).

## Risks

- **Edits are blocked** to these files until the bridge lands. Open PRs
that touch them must merge first or rebase afterwards. Earlier we saw
`module.py` (#21428, #21448), `coverage/instrumented_mode.py` and
`coverage/util.py` (#21405), and older prototype drafts.
- **Hash timing.** Hashes are taken from #22018's content. If #22018
changes before merging, they need regenerating.

## Additional Notes

None.

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@gnufede

gnufede commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

/merge -f --reason "unrelated celery ci job timeout"

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-11-24 16:35:41 UTC ℹ️ Start processing command /merge -f --reason "unrelated celery ci job timeout"


2026-11-24 16:35:45 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in main is approximately 0s (p90).


2026-11-24 16:35:59 UTC ℹ️ MergeQueue: This merge request was merged

Warning

This change was merged without running any pre merge CI checks

Reason: unrelated celery ci job timeout

@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit b4924dd into main Nov 24, 2026
875 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the gnufede/itr-coverage-opt-out-import-data branch November 24, 2026 16:35
gnufede added a commit that referenced this pull request Nov 24, 2026
Brings in #21405 (coverage import data opt-out) so the branch is current.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
gnufede added a commit that referenced this pull request Nov 24, 2026
#21405 modified coverage/util.py and coverage/instrumented_mode.py on
main, so their frozen hashes must follow. Main has no freeze entries
yet, so updating them within this PR does not lift an existing freeze.

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

4 participants