Repository navigation
[OpenTelemetry] Release IMetricsListener refs on dispose - #7924
Merged
Merged
Conversation
Release the `MeterProvider` and `IObservableInstrumentsSource` references in `OpenTelemetryMetricsListener.Dispose()` instead of only unsubscribing from `OnCollectObservableInstruments`. Versions of `Microsoft.Extensions.Diagnostics` prior to 9.0 never dispose `MetricsSubscriptionManager` (dotnet/runtime#94434), so the runtime keeps the listener rooted after the host is disposed. This kept the `MeterProvider`, and the `IServiceProvider` it references, alive. Fixes open-telemetry#6447.
Pull request dashboard statusMerged · refreshed 2026-10-13 14:39 UTC Status above doesn't look right?
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7924 +/- ##
==========================================
- Coverage 92.26% 92.25% -0.01%
==========================================
Files 363 363
Lines 20987 20989 +2
==========================================
+ Hits 19363 19364 +1
- Misses 1624 1625 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The source-release behavior lacks direct verification, and the changelog misidentifies which runtime object remains undisposed.
2 open findings
What changed in this PR
Fixes retained MeterProvider references after host disposal.
Changes:
- Clears listener-held provider and observable-source references.
- Adds a garbage-collection regression test.
- Documents the memory-leak fix.
[!NOTE]
This review was generated with GitHub Copilot.
| File | Description |
|---|---|
OpenTelemetryMetricsListener.cs |
Releases retained references during disposal. |
MeterProviderSdkTests.cs |
Tests provider collection and post-disposal behavior. |
CHANGELOG.md |
Records the fix. |
🧠 Review effort: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Address review feedback from GitHub Copilot.
martincostello
marked this pull request as ready for review
October 13, 2026 13:05
martincostello
enabled auto-merge
October 13, 2026 13:06
matt-hensley
approved these changes
Oct 13, 2026
This was referenced Nov 22, 2026
Open
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.


Fixes #6447
Changes
Release the
MeterProviderandIObservableInstrumentsSourcereferences inOpenTelemetryMetricsListener.Dispose()instead of only unsubscribing fromOnCollectObservableInstruments.Versions of
Microsoft.Extensions.Diagnosticsprior to 9.0 never disposeMetricsSubscriptionManager(dotnet/runtime#94434), so the runtime keeps the listener rooted after the host is disposed. This kept theMeterProvider, and theIServiceProviderit references, alive.Merge requirement checklist
CHANGELOG.mdfile(s) updated for non-trivial changesChanges in public API reviewed (if applicable)Footnotes
Yes, I can answer maintainer questions about the content of this PR without using AI. ↩