Skip to content

Generate opt-in instrumentation version class#19006

Merged
trask merged 3 commits into
open-telemetry:mainfrom
trask:opt-in-instrumentation-version-class
Jun 16, 2026
Merged

Generate opt-in instrumentation version class#19006
trask merged 3 commits into
open-telemetry:mainfrom
trask:opt-in-instrumentation-version-class

Conversation

@trask

@trask trask commented Jun 15, 2026

Copy link
Copy Markdown
Member

Alternative to #18600

Primarily motivated by putting the InstrumentationVersion class into the instrumentation's "correct" package (semi-related to #18428).

cc @breedx-splk @LikeTheSalad

Copilot AI 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.

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 configurable InstrumentationVersion Java class containing a VERSION constant.
  • Make InstrumenterBuilder lazily resolve the embedded instrumentation version only at build time, and only if no explicit version was set.
  • Opt okhttp-3.0 library 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.

Comment thread conventions/src/main/kotlin/otel.instrumentation-version-class.gradle.kts Outdated

Copilot AI 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.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

@trask trask marked this pull request as ready for review June 16, 2026 00:48
@trask trask requested a review from a team as a code owner June 16, 2026 00:48
@trask trask modified the milestone: v2.29.0 Jun 16, 2026

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

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.

@trask trask merged commit b156312 into open-telemetry:main Jun 16, 2026
95 checks passed
@trask trask deleted the opt-in-instrumentation-version-class branch June 16, 2026 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants