metrics-cdi icon indicating copy to clipboard operation
metrics-cdi copied to clipboard

Generic Producers

Open mseitner opened this issue 9 years ago • 2 comments

Hi,

I wonder if it's possible to have generic/default producers? I understand that I can use explicit producers, but that creates a lot of duplicated code.

@Produces
@Metric
Timer Timer = new Timer(new MyFancyReservoir());

@Timed(name = "customTimerA")
void timedMethodA() {
    // Timer name => TimedMethodBean.customTimerA
}

@Timed(name = "customTimerB")
void timedMethodB() {
    // Timer name => TimedMethodBean.customTimerB
}

mseitner avatar Jun 15 '16 14:06 mseitner

It's not possible for the time being. Metrics CDI conveniently uses the metrics registry to register custom metrics declared with @Produces without adding any other logic for the retrieval.

I agree with you and your use case makes sense. One way of doing thing would be to add support for name matching, e.g.:

@Produces
@Metric(name = "*")
Timer Timer = new Timer(new MyFancyReservoir());

Another way would be to provide a way to customise the reservoir for instance globally. I've already introduced the MetricsConfiguration class for that kind of need.

astefanutti avatar Jun 17 '16 08:06 astefanutti

@mseitner sorry for the late reply. Would the MetricsConfiguration.reservoirFunction function introduced in version 1.5.0 that enables the configuration of reservoirs solve your issue?

astefanutti avatar Jun 13 '18 06:06 astefanutti