Repository navigation
Reuse no-op metric instruments - #1732
Merged
fractalwrench merged 1 commit intoNov 27, 2026
Merged
Conversation
Return shared instances with placeholder metadata and cover reuse, inert callbacks, and shared lifecycle behavior. Fixes open-telemetry#1727 Assisted-by: Codex (GPT-6)
|
|
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the change to reuse shared no-op metric instruments.
No open issues 🎉
What changed in this PR
Reduces allocations in the Kotlin Multiplatform no-op metrics implementation by returning shared instruments, addressing #1727.
Changes:
- Converts ten no-op instrument types to singletons and updates
NoopMeterfactories to reuse them. - Documents placeholder metadata: an empty name and null unit/description.
- Adds tests for instance reuse, concurrent access, ignored callbacks, and shared lifetimes; updates existing metadata assertions.
| File | Description |
|---|---|
noop/src/commonTest/kotlin/io/opentelemetry/kotlin/NoopTests.kt |
Updates up-down counter metadata expectations. |
noop/src/commonTest/kotlin/io/opentelemetry/kotlin/metrics/NoopObservableLongUpDownCounterTest.kt |
Expects placeholder metadata. |
noop/src/commonTest/kotlin/io/opentelemetry/kotlin/metrics/NoopObservableLongGaugeTest.kt |
Expects placeholder metadata. |
noop/src/commonTest/kotlin/io/opentelemetry/kotlin/metrics/NoopObservableDoubleUpDownCounterTest.kt |
Expects placeholder metadata. |
noop/src/commonTest/kotlin/io/opentelemetry/kotlin/metrics/NoopObservableDoubleGaugeTest.kt |
Expects placeholder metadata. |
noop/src/commonTest/kotlin/io/opentelemetry/kotlin/metrics/NoopMeterTest.kt |
Adds reuse, concurrency, callback, and lifetime tests. |
noop/src/commonTest/kotlin/io/opentelemetry/kotlin/metrics/NoopLongGaugeTest.kt |
Expects placeholder metadata. |
noop/src/commonTest/kotlin/io/opentelemetry/kotlin/metrics/NoopDoubleGaugeTest.kt |
Expects placeholder metadata. |
noop/src/commonMain/kotlin/io/opentelemetry/kotlin/metrics/NoopObservableLongUpDownCounter.kt |
Converts to a singleton with placeholder metadata. |
noop/src/commonMain/kotlin/io/opentelemetry/kotlin/metrics/NoopObservableLongGauge.kt |
Converts to a singleton with placeholder metadata. |
noop/src/commonMain/kotlin/io/opentelemetry/kotlin/metrics/NoopObservableLongCounter.kt |
Converts to a singleton with placeholder metadata. |
noop/src/commonMain/kotlin/io/opentelemetry/kotlin/metrics/NoopObservableDoubleUpDownCounter.kt |
Converts to a singleton with placeholder metadata. |
noop/src/commonMain/kotlin/io/opentelemetry/kotlin/metrics/NoopObservableDoubleGauge.kt |
Converts to a singleton with placeholder metadata. |
noop/src/commonMain/kotlin/io/opentelemetry/kotlin/metrics/NoopObservableDoubleCounter.kt |
Converts to a singleton with placeholder metadata. |
noop/src/commonMain/kotlin/io/opentelemetry/kotlin/metrics/NoopMeter.kt |
Returns shared instruments instead of constructing instances. |
noop/src/commonMain/kotlin/io/opentelemetry/kotlin/metrics/NoopLongUpDownCounter.kt |
Converts to a singleton with placeholder metadata. |
noop/src/commonMain/kotlin/io/opentelemetry/kotlin/metrics/NoopLongGauge.kt |
Converts to a singleton with placeholder metadata. |
noop/src/commonMain/kotlin/io/opentelemetry/kotlin/metrics/NoopDoubleUpDownCounter.kt |
Converts to a singleton with placeholder metadata. |
noop/src/commonMain/kotlin/io/opentelemetry/kotlin/metrics/NoopDoubleGauge.kt |
Converts to a singleton with placeholder metadata. |
noop/README.md |
Documents sharing, placeholders, and no-op behavior. |
implementation/src/commonTest/kotlin/io/opentelemetry/kotlin/metrics/UpDownCounterImplTest.kt |
Updates invalid-input fallback metadata assertions. |
implementation/src/commonTest/kotlin/io/opentelemetry/kotlin/metrics/MeterProviderImplTest.kt |
Updates no-op instrument metadata assertions. |
docs/configuration.md |
Explains shared instruments and metadata when disabled. |
api/src/commonMain/kotlin/io/opentelemetry/kotlin/metrics/Instrument.kt |
Clarifies no-op metadata exceptions in API documentation. |
Review effort: Balanced
fractalwrench
enabled auto-merge (squash)
November 27, 2026 09:35
Contributor
Author
|
Thanks for reviewing Jamie! Glad I could help. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1732 +/- ##
=======================================
Coverage 91.24% 91.24%
=======================================
Files 578 578
Lines 9226 9218 -8
Branches 1684 1684
=======================================
- Hits 8418 8411 -7
Misses 407 407
+ Partials 401 400 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Goal
Return one shared instance per no-op metric type instead of allocating on each factory call. Use an empty name and null unit/description, and document these placeholders.
Fixes #1727.
Testing
./gradlew verify assembleAndroidTestpassed: 8,843 test executions across JVM, Node.js and iOS, plus static analysis, ABI and documentation checks.Android device tests and the separate CI consumer matrix were not run locally.
Codex assisted with implementation, tests, and review.