Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@Timed annotation in spring metrics

I use @Timed annotation on String Boot rest controller and it works fine. Method from controller calls method from service which is also annotated with @Timed.

However, this annotation on method in subsequent service bean doesn't work (I don't see results in /metrics). Why is it happening? Could it be fixed?

like image 400
user_x Avatar asked Aug 08 '18 14:08

user_x


1 Answers

As per Support for @Timed in any Spring-managed bean #361 you can get this behaviour by registering TimedAspect manually.

@Configuration
@EnableAspectJAutoProxy
public class AutoTimingConfiguration {
  @Bean
  public TimedAspect timedAspect(MeterRegistry registry) {
    return new TimedAspect(registry);
  }
}

Do note that as per jkschneider comment in #361:

We can revisit application of @Timed via AOP or a BPP in Boot 2.1, depending on how the community reacts to the feature.

like image 192
Karol Dowbecki Avatar answered Oct 20 '22 18:10

Karol Dowbecki