3

I am trying to capture the metrics for an override method in Java / Springboot. Below is the snippet

@Override
@Timed(value = "processor_timer", histogram = true)
public void preProcess(byte[] key, byte[] event, Headers headers) {
      super.preProcess(key, event, headers);
}

I have added this configuration as well still timer not working for the override method

import io.micrometer.core.aop.TimedAspect;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;


@Configuration
@EnableAspectJAutoProxy
public class MetricsConfig {

    @Bean
    TimedAspect timedAspect(MeterRegistry registry) {
        return new TimedAspect(registry);

    }

}

Springboot Version

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.4.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
  </parent>

I am calling the preProcess like this

@Slf4j
public abstract class Processor<T> {

    private static final String TIME_HEADER_KEY = "time";
    private static final String ERRORS_HEADER_KEY = "errors";
    String topic;

    public EventProcessor(String topic,) {
        this.topic = topic;
    }

    @Timed(value = "parent_preprocess_event", histogram = true)
    public void preProcess(byte[] key, byte[] event, Headers headers) {
           log.info("Inside parent preProcess");
           T message = extractMessage(event);
           //some business logic

        }
Gupta
  • 31
  • 2
  • Please show how you're calling `preProcess`. – chrylis -cautiouslyoptimistic- Jan 18 '21 at 06:08
  • I am calling it like this @Slf4j public abstract class Processor { private static final String TIME_HEADER_KEY = "time"; private static final String ERRORS_HEADER_KEY = "errors"; String topic; public EventProcessor(String topic,) { this.topic = topic; } @Timed(value = "parent_preprocess_event", histogram = true) public void preProcess(byte[] key, byte[] event, Headers headers) { log.info("Inside parent preProcess"); T message = extractMessage(event); //some business logic } – Gupta Jan 18 '21 at 18:49
  • Thank you @chrylis-cautiouslyoptimistic- I have added it. Any help is appreciated – Gupta Jan 18 '21 at 18:52
  • can I ask a question is a @Timed work in other classes (not controller I mean) in your project? – Armin Jan 18 '21 at 19:31
  • You still didn't show where you're _calling_ it. – chrylis -cautiouslyoptimistic- Jan 18 '21 at 22:15
  • Thank you, I closely looked at the question raised by @chrylis-cautiouslyoptimistic- and was able to resolve this by putting timer on methods where it is actually being called – Gupta Feb 09 '21 at 05:32

0 Answers0