From 4a51b78d30bda70caaa67b0f00bb3849194b49a6 Mon Sep 17 00:00:00 2001 From: mosidev Date: Tue, 13 Feb 2024 08:21:12 +0330 Subject: [PATCH] [enhancement] log duration of the feign response/exception execution in seconds --- pom.xml | 22 +++++-------------- .../wrapper/HttpResponseWrapper.java | 5 ----- .../feign/logger/HttpFeignClientLogger.java | 6 ++--- 3 files changed, 9 insertions(+), 24 deletions(-) diff --git a/pom.xml b/pom.xml index 1803187..046e791 100644 --- a/pom.xml +++ b/pom.xml @@ -1,18 +1,18 @@ 4.0.0 + com.tosan.client.http + tosan-httpclient-spring-boot-root + 3.1.6-SNAPSHOT + pom + org.springframework.boot spring-boot-starter-parent - 3.2.0 + 3.2.2 - com.tosan.client.http - tosan-httpclient-spring-boot-root - 3.1.6-SNAPSHOT - pom - tosan-httpclient-spring-boot-starter This project provides a Spring-Boot Starter that enables the additional configuration of the used @@ -81,16 +81,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - 3.11.0 - - ${java.version} - true - true - - org.apache.maven.plugins maven-surefire-plugin diff --git a/tosan-httpclient-spring-boot-resttemplate-starter/src/main/java/com/tosan/client/http/resttemplate/starter/impl/interceptor/wrapper/HttpResponseWrapper.java b/tosan-httpclient-spring-boot-resttemplate-starter/src/main/java/com/tosan/client/http/resttemplate/starter/impl/interceptor/wrapper/HttpResponseWrapper.java index 3622b22..9d0cebf 100644 --- a/tosan-httpclient-spring-boot-resttemplate-starter/src/main/java/com/tosan/client/http/resttemplate/starter/impl/interceptor/wrapper/HttpResponseWrapper.java +++ b/tosan-httpclient-spring-boot-resttemplate-starter/src/main/java/com/tosan/client/http/resttemplate/starter/impl/interceptor/wrapper/HttpResponseWrapper.java @@ -26,11 +26,6 @@ public HttpStatusCode getStatusCode() throws IOException { return this.response.getStatusCode(); } - @Override - public int getRawStatusCode() throws IOException { - return this.response.getRawStatusCode(); - } - @Override public String getStatusText() throws IOException { return this.response.getStatusText(); diff --git a/tosan-httpclient-spring-boot-starter/src/main/java/com/tosan/client/http/starter/impl/feign/logger/HttpFeignClientLogger.java b/tosan-httpclient-spring-boot-starter/src/main/java/com/tosan/client/http/starter/impl/feign/logger/HttpFeignClientLogger.java index b1c2a8a..347c9b4 100644 --- a/tosan-httpclient-spring-boot-starter/src/main/java/com/tosan/client/http/starter/impl/feign/logger/HttpFeignClientLogger.java +++ b/tosan-httpclient-spring-boot-starter/src/main/java/com/tosan/client/http/starter/impl/feign/logger/HttpFeignClientLogger.java @@ -92,7 +92,7 @@ protected Response logAndRebufferResponse(String configKey, Level logLevel, Resp responseData.put("invoked", webServiceName); int status = response.status(); responseData.put("service", getServiceName(methodTag(configKey))); - responseData.put("duration", elapsedTime + "ms"); + responseData.put("duration", elapsedTime / 1000.0 + "s"); responseData.put("status", status); if (logLevel.ordinal() >= Level.HEADERS.ordinal()) { if (!response.headers().isEmpty()) { @@ -120,7 +120,7 @@ protected IOException logIOException(String configKey, Level logLevel, IOExcepti Map exceptionData = new LinkedHashMap<>(); exceptionData.put("invoked", webServiceName); exceptionData.put("service", getServiceName(methodTag(configKey))); - exceptionData.put("duration", elapsedTime + "ms"); + exceptionData.put("duration", elapsedTime / 1000.0 + "s"); exceptionData.put("exception", ioe.getClass().getSimpleName()); exceptionData.put("message", ioe.getMessage()); if (logLevel.ordinal() >= Level.FULL.ordinal() && logger.isDebugEnabled()) { @@ -183,7 +183,7 @@ private Map> getMaskedHeaders(Map headerValues = entry.getValue(); Collection maskedHeaderValues = new ArrayList<>(); headerValues.forEach(headerValue -> { - if (headerValue != null && headerValue.length() > 0) { + if (headerValue != null && !headerValue.isEmpty()) { JsonReplaceResultDto jsonReplaceResultDto = replaceHelperDecider.checkJsonAndReplace(headerValue); if (!jsonReplaceResultDto.isJson()) { maskedHeaderValues.add(replaceHelperDecider.replace(headerName, headerValue));