I am trying to add Pointcut on execution of a method to total time taken by method to execute. But my pointcut is not getting called. Similar method which does not throws any exception , pointcut for that method is being called.I am not able to findout the exact root cause or issue with my pointcut expression.
@Pointcut(
value =
"execution(* com.customer.service.ExecuteCustomerService.initiateExecuteCustomer(..))")
private void logExecuteCustomer() {}
@Around(
value ="logExecuteCustomer()")
public Object TimerMonitoring(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature();
// calculate method execution time
long startTime = System.currentTimeMillis();
Object result = proceedingJoinPoint.proceed();
long endTime = System.currentTimeMillis();
try {
String desc =
methodSignature.getDeclaringType().getSimpleName() + "." + methodSignature.getName();
metricsService.metricsTimer(desc, (endTime - startTime));
} catch (Exception exception) {
log.error("Error while processing metrics ", exception);
}
return result;
}
Method
public void initiateExecuteCustomer(
ChargeTransaction chargeTransactionFromKafka, boolean ignoreCollectionDate)
throws CustomerException {
String key = LOGGER_KEY + chargeTransactionFromKafka.getOrderNo();
long serviceStartTime = System.currentTimeMillis();
// some java code
}
Like M.Deinum said (credit to him for that), your aspect is simply implemented incorrectly. The logging code is simply never reached in case of an exception while proceeding to the original method. Try this (untested, just copied from your sample code and edited):
Or you just avoid bits and pieces from the method signature and simply log the whole joinpoint, keeping the code simple: