Repository navigation
Conversation
Pull request dashboard statusWaiting on the author · refreshed 2026-11-28 05:17 UTC Move out of draft to request review. Status above doesn't look right?
|
There was a problem hiding this comment.
🟡 Changes recommended
Supplier and strong-reference gauges can fall back to Meter.Id callback ownership, retaining plugin class loaders when Micrometer is shared with the agent.
2 open issues
What changed in this PR
Introduces agent-specific callback ownership for Micrometer class-loader cleanup, building on #21569 while preserving standalone-library registration behavior.
Changes:
- Routes observable-meter callbacks through an internal registration abstraction.
- Uses weak SDK delegates with class-scoped ownership and explicit release on removal.
- Adds Gauge and TimeGauge regressions for disposable and shared class loaders.
| File | Description |
|---|---|
| OpenTelemetryMeterRegistryBuilder.java | Defaults to direct registration and accepts an internal override. |
| OpenTelemetryMeterRegistry.java | Passes the registrar and ownership metadata to observable meters. |
| OpenTelemetryMeter.java | Routes custom-meter callbacks through the registrar. |
| OpenTelemetryLongTaskTimer.java | Manages active-task and duration callback registrations. |
| OpenTelemetryGauge.java | Registers gauge callbacks with function ownership metadata. |
| OpenTelemetryFunctionTimer.java | Applies ownership handling to count and total-time callbacks. |
| OpenTelemetryFunctionCounter.java | Applies ownership handling to function-counter callbacks. |
| ObservableCallbackRegistrar.java | Defines registration handles, release hooks, and the direct default. |
| Internal.java | Adds the internal registrar configuration bridge. |
| MicrometerCallbackGcCloseTest.java | Tests metric export and class-loader collection. |
| GaugeRegistrar.java | Supplies disposable-loader Gauge and TimeGauge fixtures. |
| MicrometerSingletons.java | Enables the agent-specific registrar. |
| MicrometerCallbackRegistrar.java | Implements weak delegation, ownership selection, and release. |
Review effort: Balanced
There was a problem hiding this comment.
🟡 Changes recommended
The parent-only callback ownership lookup fails under sibling-loader delegation, causing the shared Meter.Id ClassValue entry to retain the application's measurement function and class loader and prevent unloading.
1 open issue
2 resolved since last review
Review effort: Balanced
| while (loader != null && loader != ownerLoader) { | ||
| loader = loader.getParent(); | ||
| if (loader == ownerLoader) { | ||
| return functionClass; | ||
| } |
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
b7a0071 to
a16a100
Compare


The Java agent's SDK can keep an undeployed application's class loader alive through Micrometer observable callbacks. The SDK now holds a weak delegate for callbacks from the agent's registry. Standalone registries still register callbacks directly. This PR and the explicit cleanup in #21569 replace #21372.
When a child application shares its parent's Micrometer, the application's measurement function or strongly held gauge object owns the callback. This includes suppliers hidden by Micrometer's own wrappers. Explicit meter removal releases the callback without waiting for the loader to unload.
The ownership check follows the parent chain and does not cover sibling-loader delegation. The shared-Micrometer regressions register directly with the agent registry and use a null thread context class loader to isolate callback ownership from the global composite and the separate SDK thread context class-loader retention issue.