Bug fix: disposing meter with same name does not dispose the shared metric#7172
Bug fix: disposing meter with same name does not dispose the shared metric#7172sseelam2 wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7172 +/- ##
==========================================
+ Coverage 89.08% 89.62% +0.54%
==========================================
Files 271 272 +1
Lines 13073 14130 +1057
==========================================
+ Hits 11646 12664 +1018
- Misses 1427 1466 +39
Flags with carried forward coverage won't be shown. Click here to find out more.
|
|
Thanks for the PR! I want to understand whether this is actually a bug or expected behavior. The OTel SDK identifies meters by (name, version, schema_url, attributes) — not by object instance. So when two new Meter("MyApp") calls produce the same identity, from the SDK's perspective there's only one Meter/Scope. When either instance is disposed, isn't it reasonable that the SDK treats it as "the Meter named MyApp is being torn down" and deactivates the associated Metric? Should we consider the current behavior a bug? |
|
My understanding is that OpenTelemetry defines Meter identity using (name, version, schema_url, attributes) mainly for attribution. Does that also imply that all Meter instances with the same identity are expected to share the same lifetime? I’m still getting familiar with the SDK, but in .NET Meter is IDisposable, and disposing one instance should ideally only affect the instruments created from that instance and not tear down the Metric if there are other Meter instances with the same identity still alive. If disposing one Meter instance is meant to deactivate metrics for all meters with the same identity, that behavior should probably be explicit. Otherwise, we could consider preventing multiple meters from being created with the same identity. |
|
This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or pushing will instruct the bot to automatically remove the label. This bot runs once per day. |
Fixes #6412
Changes
Added reference counting to
Metric.AddInstrumentReference()is called when an instrument is attached;RemoveInstrumentReference()is called on completion and only triggersDeactivateMetric(Metric)when the count reaches zero. BothBuildForSingleMetric(Metric)andBuildForMetricList(List<Metric>)inMetricStateare updated accordingly.Merge requirement checklist
AppropriateCHANGELOG.mdfiles updated for non-trivial changesChanges in public API reviewed (if applicable)