Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API Proposal]: Allow to delete an instrument inside a Meter instance #83822

Open
LGouellec opened this issue Mar 23, 2023 · 2 comments
Open
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Diagnostics.Metric enhancement Product code improvement that does NOT require public API changes/additions
Milestone

Comments

@LGouellec
Copy link

Background and motivation

For now, when you create an instance of Meter you can create multiple types of instrument (Histogram, Counter, ObservableGauge or ObservableCounter).

But you can't delete one observable gauge (for instance) previously created. The only way is to dispose the Meter instance and recreate from scratch with all instruments minus the instrument supposed to remove. It's not efficient at all.

API Proposal

 public class Meter : IDisposable
{
       private List<Instrument> _instruments = new List<Instrument>();
       // ....

      public void Remove(Instrument instrument) {
           _instruments.Remove(instrument)
     }
}

API Usage

var meter = new Meter("ServiceName");
var gauge =  meter.CreateObservableGauge(
                        key, 
                        () => new[]
                        {
                            new Measurement<double>(
                                value,
                                tags)
                        },
                        description: summary);           

meter.Remove(gauge);

Alternative Designs

No response

Risks

No response

@LGouellec LGouellec added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Mar 23, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Mar 23, 2023
@tommcdon
Copy link
Member

@noahfalk @tarekgh

@tommcdon tommcdon added this to the 8.0.0 milestone Mar 27, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Mar 27, 2023
@tommcdon tommcdon added enhancement Product code improvement that does NOT require public API changes/additions untriaged New issue has not been triaged by the area owner and removed untriaged New issue has not been triaged by the area owner labels Mar 27, 2023
@tarekgh tarekgh modified the milestones: 8.0.0, Future Mar 27, 2023
@asasine
Copy link

asasine commented Sep 20, 2023

I would think that having Instrument implement IDisposable is the canonical way to indicate that instruments are disposable. Stealing from the Observer design pattern, the instances of Instrument can hold references to their Meter and remove themself from the meter's collection when disposed. This further supports the DI model as types only need to depend on the appropriate instrument, not the meter, to accurately dispose of the instrument when the DI container disposes them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Diagnostics.Metric enhancement Product code improvement that does NOT require public API changes/additions
Projects
None yet
Development

No branches or pull requests

5 participants