title: @Timed not working despite registering TimedAspect explicitly - spring boot 2.1
body: <p>I need to measure method-metrics using micrometer @Timed annotation. As it doesn't work on arbitrary methods; i added the configuration of @TimedAspect explicitly in my spring config. Have referred to this post for exact config
  Note: have tried adding a separate config class JUST for this, as well as including the TimedAspect bean as part of my existing configuration bean</p>
  <p><a href="https://stackoverflow.com/questions/48704789/how-to-measure-service-methods-using-spring-boot-2-and-micrometer/49193908#49193908">How to measure service methods using spring boot 2 and micrometer</a></p>
  <p>Yet, it unfortunately doesn't work. The Bean is registred and the invocation from config class goes thru successfully on startup. Found this while debugging. However, the code in the @Around never seems to execute.
  No error is thrown; and im able to view the default 'system' metrics on the /metrics and /prometheus endpoint.</p>
  <p>Note: This is AFTER getting the 'method' to be invoked several times by executing a business flow. I'm aware that it probably doesn't show up in the metrics if the method isn't invoked at all</p>
  <p>Versions: spring-boot 2.1.1, spring 5.3, micrometer 1.1.4, actuator 2.1</p>
  <p>Tried everything going by the below posts:</p>
  <p><a href="https://stackoverflow.com/questions/48704789/how-to-measure-service-methods-using-spring-boot-2-and-micrometer/49193908#49193908">How to measure service methods using spring boot 2 and micrometer</a></p>
  <p><a href="https://github.com/izeye/sample-micrometer-spring-boot/tree/timed-annotation" rel="nofollow noreferrer">https://github.com/izeye/sample-micrometer-spring-boot/tree/timed-annotation</a></p>
  <p><a href="https://github.com/micrometer-metrics/micrometer/issues/361" rel="nofollow noreferrer">https://github.com/micrometer-metrics/micrometer/issues/361</a></p>
  <p>Update: So, the issue seems to be ONLY when the Timed is on an abstract method, which is called via another method. Was able to reproduce it via a simple example.  Refer to the @Timed(&quot;say_hello_example&quot;) annotation. It simply gets ignored and doesnt show up when i hit the prometheus endpoint.</p>
  <p>Code:
  Abstract Class</p>
  <pre class="lang-java prettyprint-override"><code>public abstract class AbstractUtil {
      public abstract void sayhello();
  
      public void sayhellowithtimed(String passedVar) {
          System.out.println(&quot;Passed var =&gt;&quot;+passedVar);
          System.out.println(&quot;Calling abstract sayhello....&quot;);
          sayhello();
  
      }
  }
  </code></pre>
  <p>Impl Class</p>
  <pre class="lang-java prettyprint-override"><code>@Component
  @Scope(&quot;prototype&quot;)
  public class ExampleUtil extends AbstractUtil  {
  
      public static final String HELLO = &quot;HELLO&quot;;
  
      @Timed(&quot;dirwatcher_handler&quot;)
      public void handleDirectoryWatcherChange(WatchEvent event){
          System.out.println(&quot;Event kind:&quot; + event.kind() + &quot;. File affected: &quot; + event.context());
      }
  
      @Timed(&quot;say_hello_example&quot;)
      @Override
      public void sayhello() {
          System.out.println(HELLO);
          try {
              Thread.sleep(1000);
          }
          catch (InterruptedException e) {
              e.printStackTrace();
          }
      }
  }
  
  </code></pre>
  <p>A simple DirWatcher implementation class...</p>
  <pre class="lang-java prettyprint-override"><code>package com.example;
              
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.boot.context.event.ApplicationStartedEvent;
  import org.springframework.context.ApplicationListener;
  import org.springframework.context.annotation.Scope;
  import org.springframework.context.event.ContextRefreshedEvent;
  import org.springframework.stereotype.Component;
              
  import java.io.IOException;
  import java.nio.file.*;
              
  @Component
  @Scope(&quot;prototype&quot;)
  public class StartDirWatcher implements ApplicationListener&lt;ApplicationStartedEvent&gt; {
              
      @Value(&quot;${directory.path:/apps}&quot;)
      public String directoryPath;
              
      @Autowired
      private ExampleUtil util;
              
      private void monitorDirectoryForChanges() throws IOException, InterruptedException {
          WatchService watchService = FileSystems.getDefault().newWatchService();
          Path path = Paths.get(directoryPath);
          path.register(
              watchService,
              StandardWatchEventKinds.ENTRY_CREATE,
              StandardWatchEventKinds.ENTRY_DELETE,
              StandardWatchEventKinds.ENTRY_MODIFY);
          WatchKey key;
          while ((key = watchService.take()) != null) {
              for (WatchEvent&lt;?&gt; event : key.pollEvents()) {
                  util.handleDirectoryWatcherChange(event);
                  util.sayhellowithtimed(&quot;GOD_OF_SMALL_THINGS_onAPPEvent&quot;);
              }
              key.reset();
          }
      }
              
      @Override
      public void onApplicationEvent(ApplicationStartedEvent applicationStartedEvent) {
          try {
              monitorDirectoryForChanges();
          } catch (Throwable e) {
              System.err.println(&quot;ERROR!! &quot;+e.getMessage());
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  <p>The Spring Boot Application Class</p>
  <pre class="lang-java prettyprint-override"><code>package com.example;
  
  import io.micrometer.core.aop.TimedAspect;
  import io.micrometer.core.instrument.MeterRegistry;
  import io.micrometer.prometheus.PrometheusMeterRegistry;
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.context.annotation.EnableAspectJAutoProxy;
  
  @EnableAspectJAutoProxy
  @ComponentScan
  @Configuration
  @SpringBootApplication
  public class ExampleStarter{
  
      @Bean
      MeterRegistryCustomizer&lt;PrometheusMeterRegistry&gt; metricsCommonTags() {
          return registry -&gt; registry.config().commonTags(&quot;app.name&quot;, &quot;example.app&quot;);
      }
      @Bean
      TimedAspect timedAspect(MeterRegistry reg) {
          return new TimedAspect(reg);
      }
  
      public static void main(String[] args) {
          SpringApplication.run(ExampleStarter.class, args);
      }
  
  }
  </code></pre>
  <p>The main pom.xml file</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
       xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
       xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
  &lt;groupId&gt;com.metrics.timed.example&lt;/groupId&gt;
  &lt;artifactId&gt;example-app&lt;/artifactId&gt;
  &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  &lt;build&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
              &lt;configuration&gt;
                  &lt;source&gt;1.8&lt;/source&gt;
                  &lt;target&gt;1.8&lt;/target&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/build&gt;
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;version&gt;2.1.1.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
          &lt;version&gt;2.1.1.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
      &lt;groupId&gt;io.micrometer&lt;/groupId&gt;
      &lt;artifactId&gt;micrometer-registry-prometheus&lt;/artifactId&gt;
      &lt;version&gt;1.1.2&lt;/version&gt;
  &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-aop&lt;/artifactId&gt;
          &lt;version&gt;2.1.1.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>