Skip to content

feat(v2fix): expand analyzer coverage and harden suggested fix generation#4393

Merged
darccio merged 33 commits intomainfrom
dario.castane/ktlo/v2fix-for-automatic-campaign
Feb 12, 2026
Merged

feat(v2fix): expand analyzer coverage and harden suggested fix generation#4393
darccio merged 33 commits intomainfrom
dario.castane/ktlo/v2fix-for-automatic-campaign

Conversation

@darccio
Copy link
Member

@darccio darccio commented Feb 5, 2026

What does this PR do?

  • Add additional v2fix rewrite/warn rules and import mapping for v1 to v2 changes
  • Improve probe/type handling, golden files generation, and KnownChange behavior
  • Extend test fixtures and false-positive guards to validate new rules

Motivation

We want to broaden automated migration support for dd-trace-go v2 by capturing more v1 API changes and ensuring suggested fixes are precise, stable, and safe. The added rewrites, warnings, and import mappings reduce manual migration effort, while the improved probe/type handling and stronger tests prevent false positives and regressions.

This has been implemented while testing the automatic campaigner for internal migration to deprecate v1.

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • System-Tests covering this feature have been added and enabled with the va.b.c-dev version tag.
  • There is a benchmark for any new code, or changes to existing code.
  • If this interacts with the agent in a new way, a system test has been added.
  • New code is free of linting errors. You can check this by running ./scripts/lint.sh locally.
  • Add an appropriate team label so this PR gets put in the right place for the release notes.
  • Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild.

Unsure? Have a question? Request a review!

…improve context handling

This is needed to fix the race condition that exists on concurrent evaluations.
…fixes

This update introduces functionality to generate and update golden files based on suggested fixes from the analyzer. It processes diagnostics, collects edits, and formats the output accordingly, ensuring proper handling of single and multiple messages. This enhancement improves the testing workflow for the v2fix package.

The warning-only golden files are generated for consistency/documentation but aren't validated by analysistest.RunWithSuggestedFixes. This is expected behavior from the analysistest package - it only compares when there are actual text edits to apply.
The tests require V1Usage to satisfy the KnownChange interface, and adding Clone() to the test helper makes that contract explicit so test scaffolding stays aligned with production interface changes without altering runtime behavior.
This updates probe context plumbing to capture type expressions, import literals, and helper logic for aliases, composite types, and v1-path detection so analysis is more accurate (including ChildOf option extraction) and fixes can target precise source spans without misidentifying non‑v1 symbols.
This extends the v1 import rewrite to recognize contrib subpaths and translate them to the new contrib/.../v2 path while still handling core imports, ensuring fixes produce correct module paths for both patterns.
Adds the AppSecLoginEvents known change plus wiring in main and tests so v2fix can remap TrackUserLogin(Success|Failure)Event to the new TrackUserLogin(Success|Failure) APIs and keep the golden fixtures in sync; this keeps the AppSec migration path covered and avoids false positives against the renamed helpers.
Adds the DeprecatedWithPrioritySampling KnownChange plus new golden fixture/output to cover tracer.WithPrioritySampling so the checker can emit the “has been removed” warning (priority sampling is now default) without attempting any code changes, keeping migrations focused on the new semantics.
Adds the DeprecatedWithHTTPRoundTripper KnownChange, the associated golden fixture inputs/outputs, and registers it so v2fix can detect tracer.WithHTTPRoundTripper calls and emit the “has been removed; use WithHTTPClient instead” warning; this keeps the migration checker aware of the removed option instead of letting outdated code pass silently.
Added a falsepositive fixture and regression test that runs the WithServiceName, TraceID, WithDogstatsdAddress, and sampling rule rewrites against locally defined functions/types so that the checker proves it only flags dd-trace-go v1 symbols, preventing the migration tool from warning about unrelated code that happens to share names.
Adds the ChildOfStartChild known change along with its probe/test wiring so v2fix can rewrite tracer.StartSpan(..., tracer.ChildOf(...)) into the new parent.StartChild(...) pattern, keeping option plumbing and test coverage aligned with the migration guidance.
Added composite-type cases plus the N constant to the ddtracetypes stage fixtures and taught DDTraceTypes to preserve pointer/slice/array prefixes, skip fixes when array lengths can’t be rendered, and exclude SpanContext even when wrapped so the migration checker can diagnose the expanded scenarios without corrupting the source representation.
Added a RateRule exercise to the samplingrules fixture and refreshed its golden output to show the expected tracer.Rule{…} literal, while updating DeprecatedSamplingRules to require the v1 package path, keep argument-length guards, and qualify the emitted Rule literal with the package prefix so the fixer now safely rewrites every deprecated constructor (including RateRule) into the new struct form without touching non-dd-trace-go symbols.
… generation

Use the stored type expression string to keep the original qualifier/alias in struct pointer fixes, fall back to derived types when missing, guard against non-selector calls, and reuse the package prefix helper while tightening argument checks so generated edits are safer and more accurate.
@darccio darccio added the AI Assisted AI/LLM assistance used in this PR (partially or fully) label Feb 5, 2026
@darccio darccio marked this pull request as ready for review February 5, 2026 17:59
@darccio darccio requested a review from a team as a code owner February 5, 2026 17:59
@codecov
Copy link

codecov bot commented Feb 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 55.51%. Comparing base (80bf124) to head (53a0011).

Additional details and impacted files

see 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pr-commenter
Copy link

pr-commenter bot commented Feb 5, 2026

Benchmarks

Benchmark execution time: 2026-02-12 18:58:20

Comparing candidate commit 3c92d46 in PR branch dario.castane/ktlo/v2fix-for-automatic-campaign with baseline commit 7196cbb in branch main.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 155 metrics, 9 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 ----------------------------------'

@@ -43,6 +43,9 @@ type KnownChange interface {

Copy link
Member

Choose a reason for hiding this comment

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

I think we should split the known_change.go into several files and have a package to collect them.

Copy link
Member Author

Choose a reason for hiding this comment

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

Doing it in a separate PR.

@kakkoyun
Copy link
Member

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

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: 7bd0cfc776

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

Refactor the v2fix tool to replace instances of tracer.StartSpan with parent.StartChild when using ChildOf, ensuring compliance with the new API pattern. This change enhances the migration process by aligning with the updated tracing methods while maintaining option handling and test coverage.
This change standardizes the naming convention for type extraction functions in the v2fix tool, improving code clarity and consistency.
@darccio
Copy link
Member Author

darccio commented Feb 10, 2026

@codex review

@gh-worker-devflow-routing-ef8351
Copy link

gh-worker-devflow-routing-ef8351 bot commented Feb 12, 2026

View all feedbacks in Devflow UI.

2026-02-12 08:37:34 UTC ℹ️ Start processing command /merge


2026-02-12 08:37:42 UTC ℹ️ MergeQueue: waiting for PR to be ready

This pull request is not mergeable according to GitHub. Common reasons include pending required checks, missing approvals, or merge conflicts — but it could also be blocked by other repository rules or settings.
It will be added to the queue as soon as checks pass and/or get approvals. View in MergeQueue UI.
Note: if you pushed new commits since the last approval, you may need additional approval.
You can remove it from the waiting list with /remove command.


2026-02-12 09:05:07 UTC ℹ️ MergeQueue: merge request added to the queue

The expected merge time in main is approximately 43m (p90).


2026-02-12 09:31:26 UTCMergeQueue: The checks failed on this merge request

Tests failed on this commit 019b653:

What to do next?

  • Investigate the failures and when ready, re-add your pull request to the queue!
  • If your PR checks are green, try to rebase/merge. It might be because the CI run is a bit old.
  • Any question, go check the FAQ.

@darccio
Copy link
Member Author

darccio commented Feb 12, 2026

/merge

@gh-worker-devflow-routing-ef8351
Copy link

gh-worker-devflow-routing-ef8351 bot commented Feb 12, 2026

View all feedbacks in Devflow UI.

2026-02-12 09:45:36 UTC ℹ️ Start processing command /merge


2026-02-12 09:45:47 UTC ℹ️ MergeQueue: waiting for PR to be ready

This pull request is not mergeable according to GitHub. Common reasons include pending required checks, missing approvals, or merge conflicts — but it could also be blocked by other repository rules or settings.
It will be added to the queue as soon as checks pass and/or get approvals. View in MergeQueue UI.
Note: if you pushed new commits since the last approval, you may need additional approval.
You can remove it from the waiting list with /remove command.


2026-02-12 10:03:14 UTC ℹ️ MergeQueue: merge request added to the queue

The expected merge time in main is approximately 43m (p90).


2026-02-12 10:31:47 UTCMergeQueue: The checks failed on this merge request

Tests failed on this commit 8da6860:

What to do next?

  • Investigate the failures and when ready, re-add your pull request to the queue!
  • If your PR checks are green, try to rebase/merge. It might be because the CI run is a bit old.
  • Any question, go check the FAQ.

@darccio
Copy link
Member Author

darccio commented Feb 12, 2026

/merge

@gh-worker-devflow-routing-ef8351
Copy link

gh-worker-devflow-routing-ef8351 bot commented Feb 12, 2026

View all feedbacks in Devflow UI.

2026-02-12 18:37:35 UTC ℹ️ Start processing command /merge


2026-02-12 18:37:42 UTC ℹ️ MergeQueue: waiting for PR to be ready

This pull request is not mergeable according to GitHub. Common reasons include pending required checks, missing approvals, or merge conflicts — but it could also be blocked by other repository rules or settings.
It will be added to the queue as soon as checks pass and/or get approvals. View in MergeQueue UI.
Note: if you pushed new commits since the last approval, you may need additional approval.
You can remove it from the waiting list with /remove command.


2026-02-12 19:01:47 UTC ⚠️ MergeQueue: This merge request was unqueued

dario.castane@datadoghq.com unqueued this merge request

@darccio
Copy link
Member Author

darccio commented Feb 12, 2026

/remove

@gh-worker-devflow-routing-ef8351
Copy link

gh-worker-devflow-routing-ef8351 bot commented Feb 12, 2026

View all feedbacks in Devflow UI.

2026-02-12 19:01:37 UTC ℹ️ Start processing command /remove


2026-02-12 19:01:41 UTC ℹ️ Devflow: /remove

@darccio darccio merged commit 3379e30 into main Feb 12, 2026
182 of 183 checks passed
@darccio darccio deleted the dario.castane/ktlo/v2fix-for-automatic-campaign branch February 12, 2026 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Assisted AI/LLM assistance used in this PR (partially or fully) mergequeue-status: removed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants