As of v1.0.0-rc.7 @Timed put on a method of an arbitrary Spring-managed bean is silently ignored. It would be useful to be able to generate metrics for any kind of beans (e.g. Services with non-RestTemplate remote system calls) without writing a custom AOP logic.
Is this feature is planned to be part of Milestone 1.0.0?
@elenigen I think it won't be autoconfigured in Boot 2. The Boot team is getting pretty firm on no new features. So maybe autoconfigured in Boot 2.1?
There is an open PR with an AspectJ aspect (#395). We could maybe include such an aspect in micrometer-core and leave the config to you, but it seems that a BeanPostProcessor could proxy any class with @Timed and not require AOP. There is some precedent for this (org.springframework.cache.annotation.Cacheable). Of course, this approach would only work for public API I think?
It's not clear to me why it's even necessary for arbitrary methods. Example of just timing the method body:
User lookupUser(String name, String country) {
Metrics.timer("user.lookup").record(() -> {
/* perform lookup */
});
}
I'm a little afraid of introducing something with little value that we have to pull back later. Some caution may not be so bad?
I just feel, the annotation is much less intrusive, since the metrics are not really part of the method logic itself, it's something external to monitor the method, so I was hoping if we could avoid AOP and still get this feature working, it would be the ideal solution, especially since you are saying it's feasible (Cacheable).
I can have a stab at it. It's just a lot more code without Aspectj
The TimedAspect aspect now exists in micrometer-core, but will _not_ be autoconfigured in Spring Boot 2 or micrometer-spring-legacy. We can revisit application of @Timed via AOP or a BPP in Boot 2.1, depending on how the community reacts to the feature.
To configure manually:
@Configuration
@EnableAspectJAutoProxy
public class AutoTimingConfiguration {
@Bean
public TimedAspect timedAspect(MeterRegistry registry) {
return new TimedAspect(registry);
}
}
Is there a reason why AspectJ was used instead of AOP Alliance? Both are supported by Spring, but only AOP Alliance is by Guice. Spring Transactions uses AOP Alliance (TransactionInterceptor), making it easy to leverage in Guice w/o Spring IoC.
I also think should use AOP Alliance by default. AspectJ could be a additional option.
Most helpful comment
The
TimedAspectaspect now exists inmicrometer-core, but will _not_ be autoconfigured in Spring Boot 2 ormicrometer-spring-legacy. We can revisit application of@Timedvia AOP or a BPP in Boot 2.1, depending on how the community reacts to the feature.To configure manually: