Browse Source

Log RetryException for @Retryable methods

To improve diagnostics, this commit logs a DEBUG message including the
RetryException thrown by RetryTemplate when it's used behind the scenes
for @Retryable method invocations.

Closes gh-35983
pull/35990/head
Sam Brannen 1 week ago
parent
commit
cc4c693db7
  1. 10
      spring-context/src/main/java/org/springframework/resilience/retry/AbstractRetryInterceptor.java

10
spring-context/src/main/java/org/springframework/resilience/retry/AbstractRetryInterceptor.java

@ -22,6 +22,8 @@ import java.util.concurrent.Future; @@ -22,6 +22,8 @@ import java.util.concurrent.Future;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
@ -50,6 +52,8 @@ import org.springframework.util.ClassUtils; @@ -50,6 +52,8 @@ import org.springframework.util.ClassUtils;
*/
public abstract class AbstractRetryInterceptor implements MethodInterceptor {
private static final Log logger = LogFactory.getLog(AbstractRetryInterceptor.class);
/**
* Reactive Streams API present on the classpath?
*/
@ -102,6 +106,7 @@ public abstract class AbstractRetryInterceptor implements MethodInterceptor { @@ -102,6 +106,7 @@ public abstract class AbstractRetryInterceptor implements MethodInterceptor {
.maxDelay(spec.maxDelay())
.build();
RetryTemplate retryTemplate = new RetryTemplate(retryPolicy);
String methodName = ClassUtils.getQualifiedMethodName(method, (target != null ? target.getClass() : null));
try {
return retryTemplate.execute(new Retryable<@Nullable Object>() {
@ -112,11 +117,14 @@ public abstract class AbstractRetryInterceptor implements MethodInterceptor { @@ -112,11 +117,14 @@ public abstract class AbstractRetryInterceptor implements MethodInterceptor {
}
@Override
public String getName() {
return ClassUtils.getQualifiedMethodName(method, (target != null ? target.getClass() : null));
return methodName;
}
});
}
catch (RetryException ex) {
if (logger.isDebugEnabled()) {
logger.debug("@Retryable operation '%s' failed".formatted(methodName), ex);
}
throw ex.getCause();
}
}

Loading…
Cancel
Save