0

I have a bean that has a request scope and in it there is a method that is annotated with micrometer(io.micrometer.core.annotation) @Timed but it is not showing in the metrics. It shows if the bean is in the default scope (Singleton).

@RequestScope
@Component
public class MyTask {
 //some local variables here
public MyTask() {
  //some unhelpful stuff
}
    @Timed(value = "mappingTask")
    @Override
    public void map(List<MyPojo> myApps) {
      //Some process
}

}

Is it not supposed to work with Request scope or what am I missing.

dawit
  • 195
  • 1
  • 3
  • 15

1 Answers1

0

taken from: Micrometer github issues

The original issue/question:

@Timed put on a method of an arbitrary Spring-managed bean is silently ignored.

And this was the response from Micrometer:

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);
   }
}

im not sure this is your issue, but could be worth a try.

Toerktumlare
  • 12,548
  • 3
  • 35
  • 54
  • I tried this but it did not work. I believe the issue is with the timing the **@Timed** annotation is weaved in case of **@RequestScope** annotated beans. As I said, it all works if the bean has the default scope.(Singleton) – dawit Jun 05 '19 at 01:45
  • Aspectj is compile time weaving, while Spring AOP is proxy bean (runtime) weaving. Well sorry cant help you then – Toerktumlare Jun 05 '19 at 10:05
  • Thomas, a little correction: AspectJ _can be_ used via compile-time weaving, but inside Spring is usually used via load-time weaving. The latter is also the documented way in the Spring manual. @dawit, your problem is still unsolved. Maybe you want to consider posting a real [MCVE](http://stackoverflow.com/help/mcve) which would allow others to more than just guess. Give us something we can run and analyse. I am quite sure you will get a helpful answer that way. – kriegaex Jun 14 '19 at 01:25