From a43103f14ca04c425c99d877136cc9ee3f1d4bf1 Mon Sep 17 00:00:00 2001 From: Rachel Tucker Date: Tue, 2 Aug 2016 14:21:43 -0600 Subject: [PATCH] Improved network client logging to include request id --- .../ds3client/networking/NetworkClientImpl.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ds3-sdk/src/main/java/com/spectralogic/ds3client/networking/NetworkClientImpl.java b/ds3-sdk/src/main/java/com/spectralogic/ds3client/networking/NetworkClientImpl.java index ee3790c42..8f05c98fb 100644 --- a/ds3-sdk/src/main/java/com/spectralogic/ds3client/networking/NetworkClientImpl.java +++ b/ds3-sdk/src/main/java/com/spectralogic/ds3client/networking/NetworkClientImpl.java @@ -82,6 +82,7 @@ public class NetworkClientImpl implements NetworkClient { final static private String CONTENT_CRC32C = "Content-CRC32C"; final static private int MAX_CONNECTION_PER_ROUTE = 50; final static private int MAX_CONNECTION_TOTAL = 100; + final static private String REQUEST_ID_HEADER = "x-amz-request-id"; final private ConnectionDetails connectionDetails; @@ -187,13 +188,21 @@ public WebResponse getResponse(final Ds3Request request) throws IOException { int redirectCount = 0; do { final CloseableHttpResponse response = requestExecutor.execute(); + String requestId = "Unknown"; + if (response.containsHeader(REQUEST_ID_HEADER)) { + requestId = response.getFirstHeader(REQUEST_ID_HEADER).getValue(); + } if (response.getStatusLine().getStatusCode() == HttpStatus.SC_TEMPORARY_REDIRECT) { redirectCount++; + LOG.info("Performing retry - attempt: {} for request #{}", + redirectCount, + requestId); response.close(); - LOG.info("Performing retry - attempt: {}", redirectCount); } else { - LOG.info("Got response from server"); + LOG.info("Server responded with {} for request #{}", + response.getStatusLine().getStatusCode(), + requestId); return new WebResponseImpl(response); } } while (redirectCount < this.connectionDetails.getRetries());