Skip to content

Set instrumentation version on emitted Meter scopes#18866

Merged
trask merged 1 commit into
open-telemetry:mainfrom
trask:fix-emitted-scope-version
Jun 2, 2026
Merged

Set instrumentation version on emitted Meter scopes#18866
trask merged 1 commit into
open-telemetry:mainfrom
trask:fix-emitted-scope-version

Conversation

@trask

@trask trask commented May 28, 2026

Copy link
Copy Markdown
Member

Background

TelemetryDataUtil.assertScopeVersion only walked SpanData, so metric-only modules whose emitted scope name did not match the gradle module name slipped through CI. This is what allowed the recent tomcat-jdbc-8.5 and oshi-5.0 module renames (#18838, #18854) to ship while still emitting the pre-rename scope names \u2014 the docs telemetry parser noticed in #18860, but the agent's own test runner did not.

Changes

  • Broaden assertScopeVersion to also walk MetricData (gated by the existing startsWith("test") carve-out) and hook it into InstrumentationTestRunner.waitAndAssertMetrics(...) so the same protection covers meters.
  • failsafe-3.0, dropwizard-metrics-4.0, iceberg-1.8, micrometer-1.5: scope already matches the module name; switch getMeter(...) to meterBuilder(...) with EmbeddedInstrumentationProperties version lookup so the version actually flows through.
  • oshi-5.0: scope was a pre-rename literal. The library module is alpha so flip its emitted scope directly to the module-name-aligned io.opentelemetry.oshi-5.0 (the existing version-properties lookup just works once the names match). The javaagent is stable so apply the CxfSingletons pattern: emit the legacy io.opentelemetry.oshi scope by default to preserve dashboards/filters, switch to the new scope under AgentCommonConfig.get().isV3Preview(). Add SystemMetrics/ProcessMetrics.registerObservers(Meter) overloads so the javaagent can inject a meter with the legacy scope while reusing the library observer-registration code.
  • tomcat-jdbc-8.5: javaagent-only, no library. Apply the CxfSingletons pattern: legacy io.opentelemetry.tomcat-jdbc scope by default, new io.opentelemetry.tomcat-jdbc-8.5 under v3-preview, always look up version under the new module name. Add a DbConnectionPoolMetrics.create(Meter, String) overload so tomcat-jdbc can build its own meter and inject it.
  • jmx-metrics: pre-existing scope mismatch (emits io.opentelemetry.jmx, module is jmx-metrics). Add a versionLookupName parameter to MetricRegistrar and pass io.opentelemetry.jmx-metrics from JmxMetricInsight so the emitted scope finally has a version.

Does not include the docs allow-list overrides from #18860 \u2014 once this lands the tomcat-jdbc-8.5 entry can be dropped.

@trask trask force-pushed the fix-emitted-scope-version branch 7 times, most recently from 92e3c2c to 4233cd9 Compare May 29, 2026 03:28
Test runner TelemetryDataUtil.assertScopeVersion only walked SpanData, so metric-only modules whose emitted scope name does not match the gradle module name slipped through CI. Broaden the assertion to also walk MetricData (gated by the existing startsWith("test") carve-out) and hook it into InstrumentationTestRunner.waitAndAssertMetrics(...) so the same protection covers meters.

Fix the in-tree metric-only sites that the broadened assertion catches:

* failsafe-3.0, dropwizard-metrics-4.0, iceberg-1.8, micrometer-1.5: scope already matches module name; switch getMeter(...) to meterBuilder(...) with EmbeddedInstrumentationProperties version lookup so the version actually flows through.

* oshi-5.0: scope was a pre-rename literal. The library module is alpha so flip its emitted scope directly to the module-name-aligned io.opentelemetry.oshi-5.0 (the existing version-properties lookup just works once the names match). The javaagent is stable so apply the CxfSingletons pattern: emit the legacy io.opentelemetry.oshi scope by default to preserve dashboards/filters, switch to the new scope under AgentCommonConfig.isV3Preview(). Add SystemMetrics/ProcessMetrics.registerObservers(Meter) overloads so the javaagent can inject a meter with the legacy scope while reusing the library observer-registration code.

* tomcat-jdbc-8.5: javaagent-only, no library. Apply the CxfSingletons pattern: legacy io.opentelemetry.tomcat-jdbc scope by default, new io.opentelemetry.tomcat-jdbc-8.5 under v3-preview, always look up version under the new module name. Add a DbConnectionPoolMetrics.create(Meter, String) overload so tomcat-jdbc can build its own meter and inject it.

* jmx-metrics: pre-existing scope mismatch (emits io.opentelemetry.jmx, module is jmx-metrics). Add a versionLookupName parameter to MetricRegistrar and pass io.opentelemetry.jmx-metrics from JmxMetricInsight so the emitted scope finally has a version.
@trask trask force-pushed the fix-emitted-scope-version branch from 4233cd9 to 905f9f4 Compare May 29, 2026 04:03
@jaydeluca

Copy link
Copy Markdown
Member

@trask should this still be in draft or is it ready for review?

@trask trask marked this pull request as ready for review June 2, 2026 13:55
@trask trask requested a review from a team as a code owner June 2, 2026 13:55
Copilot AI review requested due to automatic review settings June 2, 2026 13:55
@trask trask merged commit daa70a4 into open-telemetry:main Jun 2, 2026
97 checks passed
@trask trask deleted the fix-emitted-scope-version branch June 2, 2026 13:56

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 ensures metric instrumentation scopes carry an instrumentation version (like spans already do), tightening CI checks so metric-only modules can’t silently emit unversioned/incorrect scope metadata after module renames.

Changes:

  • Extend scope-version assertions to include MetricData and invoke the check from InstrumentationTestRunner.waitAndAssertMetrics(...).
  • Update multiple instrumentations to build meters via meterBuilder(...).setInstrumentationVersion(...) (using EmbeddedInstrumentationProperties) so scope versions flow into emitted metrics.
  • Preserve legacy scope names for renamed javaagent instrumentations (e.g., OSHI and tomcat-jdbc) by default while switching to new scope names under v3-preview, enabled by new/overloaded meter-based registration APIs.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
testing-common/src/main/java/io/opentelemetry/instrumentation/testing/util/TelemetryDataUtil.java Adds metric scope-version verification and shares span/metric checking logic.
testing-common/src/main/java/io/opentelemetry/instrumentation/testing/InstrumentationTestRunner.java Hooks metric scope-version verification into metric test assertions.
smoke-tests-otel-starter/spring-boot-common/src/main/java/io/opentelemetry/spring/smoketest/OtelSpringStarterSmokeTestController.java Uses a test* meter scope name to stay exempt from scope-version enforcement.
instrumentation/tomcat/tomcat-jdbc-8.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/jdbc/v8_5/TomcatConnectionPoolMetrics.java Builds a versioned meter while preserving legacy scope name unless v3-preview is enabled.
instrumentation/runtime-telemetry/library/src/main/java/io/opentelemetry/instrumentation/runtimetelemetry/RuntimeTelemetryBuilder.java Looks up meter version under the current module name even when emitting legacy scope names.
instrumentation/oshi-5.0/testing/src/main/java/io/opentelemetry/instrumentation/oshi/v5_0/AbstractSystemMetricsTest.java Introduces a deprecated scopeName() bridge so library and javaagent tests can assert different scope names.
instrumentation/oshi-5.0/testing/src/main/java/io/opentelemetry/instrumentation/oshi/v5_0/AbstractProcessMetricsTest.java Same scopeName() bridge for process metrics tests (and deprecation plumbing).
instrumentation/oshi-5.0/library/src/test/java/io/opentelemetry/instrumentation/oshi/v5_0/SystemMetricsTest.java Pins library tests to the renamed io.opentelemetry.oshi-5.0 scope.
instrumentation/oshi-5.0/library/src/test/java/io/opentelemetry/instrumentation/oshi/v5_0/ProcessMetricsTest.java Pins library tests to the renamed io.opentelemetry.oshi-5.0 scope.
instrumentation/oshi-5.0/library/src/main/java/io/opentelemetry/instrumentation/oshi/v5_0/SystemMetrics.java Builds a versioned meter and adds a deprecated Meter overload for javaagent legacy-scope injection.
instrumentation/oshi-5.0/library/src/main/java/io/opentelemetry/instrumentation/oshi/v5_0/ProcessMetrics.java Same as SystemMetrics for process metrics observers.
instrumentation/oshi-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/oshi/v5_0/SystemMetricsTest.java Pins javaagent tests to the legacy io.opentelemetry.oshi scope.
instrumentation/oshi-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/oshi/v5_0/ProcessMetricsTest.java Pins javaagent tests to the legacy io.opentelemetry.oshi scope.
instrumentation/oshi-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/oshi/v5_0/MetricsRegistration.java Builds a versioned meter while switching scope name based on v3-preview, reusing library registration via meter overloads.
instrumentation/micrometer/micrometer-1.5/library/src/main/java/io/opentelemetry/instrumentation/micrometer/v1_5/OpenTelemetryMeterRegistryBuilder.java Constructs a versioned meter for the Micrometer bridge registry.
instrumentation/jmx-metrics/library/src/main/java/io/opentelemetry/instrumentation/jmx/internal/engine/MetricRegistrar.java Accepts a versionLookupName and builds a versioned meter for a possibly-legacy scope name.
instrumentation/jmx-metrics/library/src/main/java/io/opentelemetry/instrumentation/jmx/internal/engine/JmxMetricInsight.java Supplies the module-aligned version lookup name for JMX metrics while keeping the legacy scope name.
instrumentation/iceberg-1.8/library/src/main/java/io/opentelemetry/instrumentation/iceberg/v1_8/IcebergMetricsReporter.java Switches to a versioned meter construction.
instrumentation/failsafe-3.0/library/src/main/java/io/opentelemetry/instrumentation/failsafe/v3_0/FailsafeTelemetry.java Uses a versioned meter for emitted metrics.
instrumentation/dropwizard/dropwizard-metrics-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/dropwizardmetrics/v4_0/DropwizardMetricsAdapter.java Uses a versioned meter for Dropwizard metric bridging.
instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbConnectionPoolMetrics.java Adds a deprecated create(Meter, String) overload to support legacy-scope javaagent meters while reusing the same metric definitions.

* @deprecated Exists only so the javaagent test can pin the pre-rename {@code
* io.opentelemetry.oshi} scope; to be removed in 3.0 once v3-preview becomes the default.
*/
@Deprecated // to be remove
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.

4 participants