From fd80e8eaeff62b3d47c0552352e73506b3d7538a Mon Sep 17 00:00:00 2001 From: Tomasz Nurkiewicz Date: Tue, 16 Dec 2014 10:20:38 +0100 Subject: [PATCH] [#107] Logging response time of every REST call as well, easier to track individual requests by correlation ID --- .../infrastructure/web/resttemplate/MetricsAspect.groovy | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/micro-infra-spring-base/src/main/groovy/com/ofg/infrastructure/web/resttemplate/MetricsAspect.groovy b/micro-infra-spring-base/src/main/groovy/com/ofg/infrastructure/web/resttemplate/MetricsAspect.groovy index 9baa750f..853c971b 100644 --- a/micro-infra-spring-base/src/main/groovy/com/ofg/infrastructure/web/resttemplate/MetricsAspect.groovy +++ b/micro-infra-spring-base/src/main/groovy/com/ofg/infrastructure/web/resttemplate/MetricsAspect.groovy @@ -2,6 +2,7 @@ package com.ofg.infrastructure.web.resttemplate import com.codahale.metrics.MetricRegistry import groovy.transform.CompileStatic +import groovy.util.logging.Slf4j import org.aspectj.lang.ProceedingJoinPoint import org.aspectj.lang.annotation.Around import org.aspectj.lang.annotation.Aspect @@ -12,6 +13,7 @@ import static org.springframework.util.StringUtils.trimTrailingCharacter @Aspect @CompileStatic +@Slf4j class MetricsAspect { private static final String PREFIX = RestOperations.class.simpleName @@ -26,7 +28,11 @@ class MetricsAspect { final Object url = pjp.args[0] final String name = metricName(url) return metricRegistry.timer(name).time { - return pjp.proceed() + final long startTime = System.currentTimeMillis() + Object result = pjp.proceed() + final long done = System.currentTimeMillis() - startTime + log.debug("Calling '$url' took ${done}ms") + return result } }