From e0120df86d864598c7e3673da3a126d4cf1768e5 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Fri, 25 May 2018 09:40:38 +0200 Subject: [PATCH] Adding moar logging --- .../client/feign/LazyTracingFeignClient.java | 3 +- .../FeignClientServerErrorTests.java | 39 +++++++++++++------ 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/client/feign/LazyTracingFeignClient.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/client/feign/LazyTracingFeignClient.java index f25bde744..c93cc9c4b 100644 --- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/client/feign/LazyTracingFeignClient.java +++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/client/feign/LazyTracingFeignClient.java @@ -49,7 +49,8 @@ class LazyTracingFeignClient implements Client { @Override public Response execute(Request request, Request.Options options) throws IOException { if (log.isDebugEnabled()) { - log.debug("Sending a request via tracing feign client"); + log.debug("Sending a request via tracing feign client [" + tracingFeignClient() + "] " + + "and the delegate [" + this.delegate + "]"); } return tracingFeignClient().execute(request, options); } diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/client/feign/servererrors/FeignClientServerErrorTests.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/client/feign/servererrors/FeignClientServerErrorTests.java index 04a27b7d7..0cc4aee60 100644 --- a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/client/feign/servererrors/FeignClientServerErrorTests.java +++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/client/feign/servererrors/FeignClientServerErrorTests.java @@ -22,13 +22,15 @@ import java.util.Optional; import brave.Tracing; import brave.sampler.Sampler; +import com.netflix.hystrix.exception.HystrixRuntimeException; +import com.netflix.loadbalancer.BaseLoadBalancer; +import com.netflix.loadbalancer.ILoadBalancer; +import com.netflix.loadbalancer.Server; +import feign.Logger; import feign.codec.Decoder; import feign.codec.ErrorDecoder; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.Ignore; -import org.springframework.test.annotation.DirtiesContext; -import zipkin2.Span; import org.awaitility.Awaitility; import org.junit.Before; import org.junit.Test; @@ -37,17 +39,18 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.cloud.sleuth.instrument.web.TraceWebServletAutoConfiguration; -import org.springframework.cloud.sleuth.util.ArrayListSpanReporter; import org.springframework.cloud.client.loadbalancer.LoadBalanced; -import org.springframework.cloud.openfeign.EnableFeignClients; -import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.netflix.ribbon.RibbonClient; import org.springframework.cloud.netflix.ribbon.RibbonClients; +import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.cloud.sleuth.instrument.web.TraceWebServletAutoConfiguration; +import org.springframework.cloud.sleuth.util.ArrayListSpanReporter; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.bind.annotation.RequestHeader; @@ -55,12 +58,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; +import zipkin2.Span; -import com.netflix.hystrix.exception.HystrixRuntimeException; -import com.netflix.loadbalancer.BaseLoadBalancer; -import com.netflix.loadbalancer.ILoadBalancer; -import com.netflix.loadbalancer.Server; - +import static org.assertj.core.api.Assertions.fail; import static org.assertj.core.api.BDDAssertions.then; /** @@ -96,6 +96,7 @@ public class FeignClientServerErrorTests { try { log.info("sending a request"); this.feignInterface.internalError(); + fail("Must throw an exception"); } catch (HystrixRuntimeException e) { log.info("Expected exception thrown", e); } @@ -117,6 +118,7 @@ public class FeignClientServerErrorTests { try { log.info("sending a request"); this.feignInterface.notFound(); + fail("Must throw an exception"); } catch (HystrixRuntimeException e) { log.info("Expected exception thrown", e); } @@ -158,6 +160,7 @@ public class FeignClientServerErrorTests { try { log.info("sending a request"); this.customConfFeignInterface.ok(); + fail("Must throw an exception"); } catch (HystrixRuntimeException e) { log.info("Expected exception thrown", e); } @@ -179,6 +182,7 @@ public class FeignClientServerErrorTests { try { log.info("sending a request"); this.customConfFeignInterface.notFound(); + fail("Must throw an exception"); } catch (HystrixRuntimeException e) { log.info("Expected exception thrown", e); } @@ -225,6 +229,10 @@ public class FeignClientServerErrorTests { return Sampler.ALWAYS_SAMPLE; } + @Bean + Logger.Level feignLoggerLevel() { + return Logger.Level.FULL; + } } @FeignClient(value = "fooservice") @@ -275,6 +283,7 @@ public class FeignClientServerErrorTests { @RequestHeader("X-B3-SpanId") String spanId, @RequestHeader("X-B3-ParentSpanId") String parentId) { log.info("Will respond with internal error"); + logHeaders(traceId, spanId, parentId); throw new RuntimeException("Internal Error"); } @@ -284,6 +293,7 @@ public class FeignClientServerErrorTests { @RequestHeader("X-B3-SpanId") String spanId, @RequestHeader("X-B3-ParentSpanId") String parentId) { log.info("Will respond with not found"); + logHeaders(traceId, spanId, parentId); return new ResponseEntity<>("not found", HttpStatus.NOT_FOUND); } @@ -293,8 +303,13 @@ public class FeignClientServerErrorTests { @RequestHeader("X-B3-SpanId") String spanId, @RequestHeader("X-B3-ParentSpanId") String parentId) { log.info("Will respond with OK"); + logHeaders(traceId, spanId, parentId); return new ResponseEntity<>("ok", HttpStatus.OK); } + + private void logHeaders(String traceId, String spanId, String parentId) { + log.info("Trace [" + traceId + "], span [" + spanId + "], parent [" + parentId + "]"); + } } @Configuration