In my application, I have a use case where I have to monitor a method by the argument value it is supplied. I have to expose the metrics to Prometheus endpoint. However, the function is a common function and is used by many different classes. I am trying to get the value passed in the method parameter to @Timed, so as to distinguish between different behaviors this function would exhibit based on the parameter value passed.
I tried using @Timed annotation but could not get the @Timed annotation expose the function parameter as a metric to Prometheus.
@Timed("getFooContent")
public void getFooContent(Arg1 arg1, Arg2 arg2) {
//some code....
}
There isn't a way to include the parameters in the timer's tags using just the annotation. Micrometer provides the annotation for simple use cases, and recommends using the programmatic approach when you need something more complex.
You should use the record
method on the timer and wrap your code in that.
registry.timer("myclass.getFooContent", Tags.of("arg1", arg1)).record(() -> {
//some code...
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With