My Rest Api是在Spring Boot中开发的,对于日志记录我们使用的是Splunk和Spring AOP。我的问题是如何计算被调用的所有内部服务的响应时间。现在,我能够得到端到端的响应时间。我们需要这个来在Splunk中创建仪表板来跟踪Api的性能。
这是使用AspectJ的@Around注释的示例。
@Aspect
@Configuration
public class MethodExecutionCalculationAspect {
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Around("@annotation(com.in28minutes.springboot.tutorial.basics.example.aop.TrackTime)")
public void around(ProceedingJoinPoint joinPoint) throws Throwable {
long startTime = System.currentTimeMillis();
joinPoint.proceed();
long timeTaken = System.currentTimeMillis() - startTime;
logger.info("Time Taken by {} is {}", joinPoint, timeTaken);
}
}
所以,我认为这就是你想要做的。