Skip to content

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

Open
darccio wants to merge 14 commits intomainfrom
dario.castane/ktlo/v2fix-for-automatic-campaign
Open

feat(v2fix): expand analyzer coverage and harden suggested fix generation#4393
darccio wants to merge 14 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.18%. Comparing base (4183b8a) to head (7bd0cfc).
⚠️ Report is 1 commits behind head on main.

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-05 18:26:31

Comparing candidate commit 7bd0cfc in PR branch dario.castane/ktlo/v2fix-for-automatic-campaign with baseline commit 4183b8a in branch main.

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

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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants