You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's not very clear to me the best practice for plumbing the metrics throughout my codebase? The example just uses a simple main function; however, my use case is much more complex with multiple different classes using composition.
If I needed to increment a counter in one of the functions in those classes how do I sanely pass down that Counter Object without having to modify every single constructor/function declaration to accept a bunch of Counter/Gauge/etc.. metrics? Since global variables are discouraged, I honestly don't see a realistic way to do this.
I've thought about member reference variables and passing the objects through constructors but that does not work either since the registry owns the metrics objects and I would still have to change all constructor signatures. and using a map does not help with Family is templated to use each different metric. Therefore if a class needed both Guage and Counter they would have to stored in separate maps and then dependency injected into the constructor.
any guidance would be very appreciated.
The text was updated successfully, but these errors were encountered:
I also had the same issue for one of our projects. What i did was implement my own Collectable Class which inherits from ::prometheus::Collactable in this i create the MetricFamily Objects like Gauge, Counter etc.
Inside my Classes i manage things i want to counter as simple ìntsordoubles` and then create Metrics from them.
If i had the time next week i can post some example.
It's not very clear to me the best practice for plumbing the metrics throughout my codebase? The example just uses a simple main function; however, my use case is much more complex with multiple different classes using composition.
Basically How do I avoid doing this:
If I needed to increment a counter in one of the functions in those classes how do I sanely pass down that Counter Object without having to modify every single constructor/function declaration to accept a bunch of Counter/Gauge/etc.. metrics? Since global variables are discouraged, I honestly don't see a realistic way to do this.
I've thought about member reference variables and passing the objects through constructors but that does not work either since the registry owns the metrics objects and I would still have to change all constructor signatures. and using a map does not help with Family is templated to use each different metric. Therefore if a class needed both Guage and Counter they would have to stored in separate maps and then dependency injected into the constructor.
any guidance would be very appreciated.
The text was updated successfully, but these errors were encountered: