Skip to content

Rerun build-time instrumentation when a classpath class body changes - #13384

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 3 commits into
masterfrom
dougqh/build-time-instrument-classpath-input
Nov 12, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 3 commits into
masterfrom
dougqh/build-time-instrument-classpath-input

Conversation

@dougqh

@dougqh dougqh commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

Makes build-time instrumentation rerun when any class on the compile classpath changes, not just when its signatures change. A body-only change to a helper in another source set or project could reuse a cached compile, whose generated $Muzzle side class still described the old code.

Motivation

validate_build: [false] rebuilds the agent and compares it with the build job's jars. It fails on #13357, #13358 and #13359, while master passes. On #13358 the jardiff shows one file differing between two builds of the same commit: inst/datadog/trace/instrumentation/micronaut/v4_0/MicronautInstrumentation$Muzzle.classdata.

The build-time instrumentation runs as a doLast on each main compile task. It scans the tracer's advice and helpers to find the classes, methods and fields they require from the application's libraries, and records those requirements in $Muzzle. At runtime, Muzzle checks those requirements against the application's class loader to determine library compatibility.

Although AbstractCompile.getClasspath() is annotated with @Classpath, JavaCompile.getClasspath() overrides it with @CompileClasspath. The latter fingerprints the classpath's application binary interface (ABI) for compile avoidance and ignores method-body changes. A helper's implementation can change its library requirements while its own ABI stays the same.

#13358 changed a method body in MicronautDecorator, in the module's main_java17 source set, which is on compileJava's classpath. The ABI didn't change, so the build job reused a cached compileJava whose $Muzzle was computed against the old decorator, and a cacheless rebuild produced a different one.

Beyond CI, a cached build could ship muzzle references that don't match the helper code.

Additional Notes

  • This bug surfaced after Introduce a Gradle S3 build cache #12604.
  • The fix registers the compile task's classpath as an extra input named instrumentationCompileClasspath, using the private INSTRUMENTATION_COMPILE_CLASSPATH constant. Its ClasspathNormalizer tracks full class contents, including method bodies, while ignoring absolute paths, JAR entry order and timestamps, so cache entries still relocate.
  • The existing buildTimeInstrumentationPlugin input uses the same normalizer to track the ByteBuddy plugins and their dependencies, whose implementation also affects the instrumented output. The new input tracks the classes those plugins resolve and inspect.
  • instrumentationCompileClasspath tracks classpath only. The worker's assembled instrumentingClassPath also contains additionalClasspath and tmpUninstrumentedClasses.
  • The trade-off: compile tasks that use build-time instrumentation (the instrumentation modules and otel-bootstrap) now rerun on any classpath class change, including body-only ones, instead of hitting the cache. That's the price of the instrumentation reading those bodies.
  • Test: BuildTimeInstrumentationPluginTest gains a TestKit case that changes only a method body in a dependency project and asserts :compileJava reruns. Without the fix it fails with expected: SUCCESS but was: UP_TO_DATE; with the fix all 4 tests in the class pass. The rest of the buildSrc suite passes too (the JVM-path assertions in TestJvmConstraintsPluginTest depend on which JDK 17 is JAVA_HOME; with Zulu 17 they pass).
  • Real module check: in micronaut-http-server-netty-4.0, changing only a method body in MicronautDecorator (main_java17) now reruns compileJava.
  • A pre-existing formatting violation in call-site-instrumentation-plugin/.../PluginApplication.java on master fails :call-site-instrumentation-plugin:spotlessJavaCheck. It's unrelated and left out here.

Gradle best-practices audit (scoped to buildSrc/.../plugin/instrument/ and its consumers). These are existing findings, out of scope here, and worth follow-ups:

  • dont_access_project_instance_inside_task (High): InstrumentPostProcessingAction injects Project and calls project.configurations.named(…) inside the doLast action, which blocks the configuration cache.
  • avoid_eager_file_collection_apis (High): it.source.isEmpty in the matching { } predicate resolves each compile task's sources at configuration time.
  • use_attributes_on_configurations (High): the resolvable buildTimeInstrumentationPlugin configuration has no attributes, and both consumers select configuration = "buildTimeInstrumentationToolingPlugins" by name.
  • default_path_sensitivities (Medium, heuristic): the additionalClasspath and includeClassDirectories inputs default to absolute path sensitivity.

🤖 Generated with Claude Code

Build-time instrumentation runs as a post-compile step and reads classpath
classes beyond their signatures: muzzle records which library methods a helper
calls. The compile task's classpath input only fingerprints the ABI (compile
avoidance), so a change to a helper's method body in another source set or
project left the compile, and its generated $Muzzle side class, cached and
stale.

Register the classpath as an instrumentation input with full classpath
normalization, so any class change reruns it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh dougqh added type: bug fix Bug fix tag: no release notes Changes to exclude from release notes tag: ai generated Largely based on code generated by an AI or LLM comp: build labels Nov 11, 2026
@dougqh
dougqh marked this pull request as ready for review November 11, 2026 22:18
@dougqh
dougqh requested review from a team as code owners November 11, 2026 22:18
@dougqh
dougqh requested review from bric3 and removed request for a team November 11, 2026 22:18
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 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-11T22:20:46.496699Z 5a3c62c Draft marked ready
ℹ️ 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.

@dougqh
dougqh requested review from bric3 and removed request for bric3 November 11, 2026 22:18

@datadog-official datadog-official 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 extra classpath input covers body-only dependency changes that ABI-based compile avoidance misses, preventing reuse of stale $Muzzle output.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 5a3c62c

@datadog-official

This comment has been minimized.

@dd-octo-sts

dd-octo-sts Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 14.01 s 14.03 s [-0.9%; +0.7%] (no difference)
startup:insecure-bank:tracing:Agent 12.97 s 13.00 s [-1.0%; +0.5%] (no difference)
startup:petclinic:appsec:Agent 17.02 s 16.33 s [-0.0%; +8.5%] (no difference)
startup:petclinic:iast:Agent 16.94 s 16.91 s [-0.5%; +0.9%] (no difference)
startup:petclinic:profiling:Agent 16.68 s 16.91 s [-2.5%; -0.3%] (maybe better)
startup:petclinic:sca:Agent 17.08 s 16.96 s [-0.3%; +1.8%] (no difference)
startup:petclinic:tracing:Agent 16.09 s 16.22 s [-1.7%; +0.1%] (no difference)

Commit: d8c300ae · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

@AlexeyKuznetsov-DD AlexeyKuznetsov-DD 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.

Awesome catch, left minor comment about test.

The test's ByteBuddy plugin now calls lib.Helper.value() through the
instrumenting class loader and records the result as a field, so each build
asserts instrumentation saw that build's helper body, not just that the
compile reran.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh

dougqh commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

/merge

@gh-worker-devflow-routing-ef8351

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

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-11-12 02:44:44 UTC ℹ️ Start processing command /merge


2026-11-12 02:45:22 UTC ℹ️ MergeQueue: Pull request is not mergeable yet

It will be processed automatically as soon as GitHub reports it as mergeable. View in MergeQueue UI.

  • Run /code blockers to see what is blocking it.
  • Run /remove to cancel it.

2026-11-12 07:26:05 UTC ⚠️ MergeQueue: This merge request was unqueued

devflow unqueued this merge request: It did not become mergeable within the expected time

@bric3 bric3 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.

Great catch.

chore: Completed code comments., and tweaked the code a tiny bit

Use kotlin extension function, and a constant for the inout name.

Co-authored-by: Brice Dutheil <brice.dutheil@gmail.com>
@bric3 bric3 mentioned this pull request Nov 12, 2026
8 tasks done
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit 17fdf09 into master Nov 12, 2026
697 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the dougqh/build-time-instrument-classpath-input branch November 12, 2026 11:27
@github-actions github-actions Bot added this to the 1.69.0 milestone Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tag: ai generated Largely based on code generated by an AI or LLM tag: no release notes Changes to exclude from release notes type: bug fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants