nexogen-international / Nexogen.Libraries.Metrics

Library for collecting application metrics in .NET and exporting them to Prometheus
MIT License
61 stars 9 forks source link

Provide a way to create IMetrics outside of ```AddPrometheus()``` extension method #22

Closed gideonkorir closed 6 years ago

gideonkorir commented 6 years ago

I'm building a background service that I wanted to collect metrics from the background service & expose them using http endpoint. Unfortunately there is no easy way to share the metrics unless you resolve metrics from the service provider, can we provide a method that has an optional metrics parameter?

 AddPrometheus(this IServiceCollection services, IMetrics metrics = null)
{
    metrics = metrics ?? new PrometheusMetrics();
    //rest of code
}
ahoka commented 6 years ago

That makes sense, yes.

gideonkorir commented 6 years ago

@ahoka does it make sense to add a method signature like:

AddPrometheus<T>(this IServiceCollection services, T metrics) where T : IMetrics, IExposable

The reason for that is because within the AddPrometheus method we are registering both IMetrics and IExposable and those two interfaces aren't directly related

ahoka commented 6 years ago

That's reasonable. Please go ahead and create a pull request.