Repository navigation
Conversation
Co-authored-by: Copilot App <[email protected]>
Pull request dashboard statusWaiting on maintainers · refreshed 2026-11-23 13:22 UTC Merge when ready. Status above doesn't look right?
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the callback and class-loader retention changes.
No open issues 🎉
What changed in this PR
Reduces callback and class-loader retention in the metrics SDK. Live registrations still retain callbacks, and collections that already captured a registration may invoke it after closure.
Changes:
- Clears registration references when observable instrument handles close.
- Holds the registering thread’s context class loader weakly, using
nullif it is unavailable. - Adds garbage-collection regression tests for callback release and class-loader fallback and restoration.
| File | Description |
|---|---|
| sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkObservableInstrumentTest.java | Verifies callback release after closure and updates repeated-close log assertions. |
| sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/internal/state/CallbackRegistrationTest.java | Tests absent and collected registration loaders, including collection-thread loader restoration. |
| sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkObservableInstrument.java | Atomically clears registration references on close and updates closed-state diagnostics. |
| sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/state/CallbackRegistration.java | Replaces strong context-class-loader retention with a weak reference. |
Review effort: Balanced
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9045 +/- ##
=========================================
Coverage 90.45% 90.45%
Complexity 11181 11181
=========================================
Files 1032 1032
Lines 30507 30507
Branches 3992 3992
=========================================
Hits 27595 27595
Misses 1935 1935
Partials 977 977 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
trask
marked this pull request as ready for review
November 20, 2026 06:40
laurit
approved these changes
Nov 23, 2026
This branch has not been deployed
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.
A metric callback registration no longer keeps the registering thread's context class loader alive. Before this change, an undeployed web app could stay in memory for the life of the JVM.
For example, under the Java agent:
shop.warregisters a gauge during startup and never closes it.shop.war's class loader keeps the callback alive, so it should go away with the app.shop.war's loader during startup.Neither the loader nor the callback is ever collected, so every redeploy leaks another copy of the app.
If the loader has been collected, the callback now runs with a
nullcontext class loader, as it did on the default periodic reader before #8091. The SDK still holds live callbacks strongly until they're closed.