Generate opt-in instrumentation version class#19006
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces an opt-in mechanism for instrumentation libraries to supply their instrumentation version via a generated Java class (instead of always reading META-INF/...properties at runtime), and updates InstrumenterBuilder to only fall back to embedded properties when a version wasn’t explicitly provided. This supports Android-sensitive environments by avoiding resource reads when instrumentations opt in.
Changes:
- Add a new Gradle convention plugin (
otel.instrumentation-version-class) that generates a configurableInstrumentationVersionJava class containing aVERSIONconstant. - Make
InstrumenterBuilderlazily resolve the embedded instrumentation version only at build time, and only if no explicit version was set. - Opt
okhttp-3.0library instrumentation into the generated version class and set the instrumenter version via builder customization.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/OkHttpClientInstrumenterBuilderFactory.java | Sets the instrumentation version explicitly using the generated InstrumentationVersion.VERSION. |
| instrumentation/okhttp/okhttp-3.0/library/build.gradle.kts | Applies the new generator plugin and configures the generated class’ fully qualified name. |
| instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterBuilder.java | Defers embedded version lookup until instrumenter build time and only when needed. |
| conventions/src/main/kotlin/otel.instrumentation-version-class.gradle.kts | New convention plugin wiring generation into the main source set and build tasks. |
| conventions/src/main/kotlin/io/opentelemetry/instrumentation/gradle/InstrumentationVersionClassExtension.kt | Adds a Gradle extension to configure the generated class name. |
| conventions/src/main/kotlin/io/opentelemetry/instrumentation/gradle/GenerateInstrumentationVersionClassTask.kt | Implements the task that generates the Java source containing the VERSION constant. |
laurit
left a comment
There was a problem hiding this comment.
I think I like this more since we need to add the version file only for instrumentations that android uses and I guess they don't care about other instrumentations besides okhttp.
Alternative to #18600
Primarily motivated by putting the InstrumentationVersion class into the instrumentation's "correct" package (semi-related to #18428).
cc @breedx-splk @LikeTheSalad