micrometer-metrics / micrometer

An application observability facade for the most popular observability tools. Think SLF4J, but for observability.
https://micrometer.io
Apache License 2.0
4.48k stars 991 forks source link

Timed annotation framework support and TimedAspect usage not clear enough #4621

Open shakuzen opened 2 years ago

shakuzen commented 2 years ago

See https://github.com/micrometer-metrics/micrometer/issues/2930.

We've previously added clarification around this usage, but it could be more explicit that you should not use the TimedAspect AND Spring Boot's @Timed support, because it results in double instrumentation, potentially with the same meter name but different tags, which is notably a problem currently if you're using the Prometheus registry. Even if you're not using the Prometheus registry, though, you probably don't want the double instrumentation and meters for the same timing.

jbotuck commented 2 years ago

OK. I'm clear that I shouldn't use both, but it is very unclear as to when Spring Boot's @Timed support applies. The micrometer docs say

Micrometer’s Spring Boot configuration does not recognize @Timed on arbitrary methods

And Spring boot's docs say

You can use the @Timed annotation from the io.micrometer.core.annotation package with several of the supported technologies described earlier. If supported, you can use the annotation at either the class level or the method level.

For example, the following code shows how you can use the annotation to instrument all request mappings in a @RestController

Is RestController just an example? Or does the annotation ONLY work on the controller. If it is just an example then how am I to know if I'm annotating a supported method or an arbitrary method?

jonatan-ivanov commented 2 years ago

As far as I know it is only @RestController and @Controller. @jbotuck, we might need an issue/pr for Boot's repo to update this, do you want to create one?

shakuzen commented 9 months ago

Based on the previous comments, I think this probably should be opened as a documentation update to Spring Boot's docs. I've transferred it from micrometer-docs to the micrometer repo for now since the corresponding Micrometer docs are in this repo now. Is there anything we can clarify in the Micrometer docs or is this only about the Spring Boot support?