Skip to content
This repository was archived by the owner on Sep 26, 2023. It is now read-only.

Commit 1575715

Browse files
feat: add retry logging (#1160)
* feat: add retry logging * formatting * change level to FINEST * update based on comments * nit
1 parent b7646a3 commit 1575715

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Diff for: gax/src/main/java/com/google/api/gax/retrying/BasicRetryingFuture.java

+18
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
import java.util.concurrent.CancellationException;
4242
import java.util.concurrent.ExecutionException;
4343
import java.util.concurrent.RejectedExecutionException;
44+
import java.util.logging.Level;
45+
import java.util.logging.Logger;
4446

4547
/**
4648
* For internal use only.
@@ -65,6 +67,8 @@ class BasicRetryingFuture<ResponseT> extends AbstractFuture<ResponseT>
6567
private volatile ApiFuture<ResponseT> latestCompletedAttemptResult;
6668
private volatile ApiFuture<ResponseT> attemptResult;
6769

70+
private static final Logger LOG = Logger.getLogger(BasicRetryingFuture.class.getName());
71+
6872
BasicRetryingFuture(
6973
Callable<ResponseT> callable,
7074
RetryAlgorithm<ResponseT> retryAlgorithm,
@@ -166,6 +170,20 @@ void handleAttempt(Throwable throwable, ResponseT response) {
166170
retryAlgorithm.createNextAttempt(throwable, response, attemptSettings);
167171
boolean shouldRetry = retryAlgorithm.shouldRetry(throwable, response, nextAttemptSettings);
168172
if (shouldRetry) {
173+
// Log retry info
174+
if (LOG.isLoggable(Level.FINEST)) {
175+
LOG.log(
176+
Level.FINEST,
177+
"Retrying with:\n{0}\n{1}\n{2}\n{3}",
178+
new Object[] {
179+
"enclosingMethod: " + callable.getClass().getEnclosingMethod() != null
180+
? callable.getClass().getEnclosingMethod().getName()
181+
: "",
182+
"attemptCount: " + attemptSettings.getAttemptCount(),
183+
"delay: " + attemptSettings.getRetryDelay(),
184+
"retriableException: " + throwable
185+
});
186+
}
169187
tracer.attemptFailed(throwable, nextAttemptSettings.getRandomizedRetryDelay());
170188
attemptSettings = nextAttemptSettings;
171189
setAttemptResult(throwable, response, true);

0 commit comments

Comments
 (0)