Merge remote-tracking branch 'origin/2.2.x'

# Conflicts:
#	spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/client/feign/TraceLoadBalancerFeignClient.java
#	tests/spring-cloud-sleuth-instrumentation-feign-tests/src/test/java/org/springframework/cloud/sleuth/instrument/feign/issues/issue1125/ManuallyCreatedLoadBalancerFeignClientTests.java
#	tests/spring-cloud-sleuth-instrumentation-feign-tests/src/test/java/org/springframework/cloud/sleuth/instrument/feign/issues/issue1125delegates/ManuallyCreatedDelegateLoadBalancerFeignClientTests.java
This commit is contained in:
Olga Maciaszek-Sharma
2020-04-08 11:12:54 +02:00
3 changed files with 30 additions and 21 deletions

View File

@@ -66,7 +66,12 @@ public class TraceFeignBlockingLoadBalancerClient
Response response = null;
Span fallbackSpan = tracer().nextSpan().start();
try {
response = super.execute(request, options);
if (delegateIsALoadBalancer()) {
response = getDelegate().execute(request, options);
}
else {
response = super.execute(request, options);
}
if (LOG.isDebugEnabled()) {
LOG.debug("After receive");
}
@@ -97,6 +102,10 @@ public class TraceFeignBlockingLoadBalancerClient
}
}
private boolean delegateIsALoadBalancer() {
return getDelegate() instanceof FeignBlockingLoadBalancerClient;
}
private Tracer tracer() {
if (tracer == null) {
tracer = beanFactory.getBean(Tracer.class);

View File

@@ -57,7 +57,7 @@ import static org.assertj.core.api.BDDAssertions.then;
public class ManuallyCreatedLoadBalancerFeignClientTests {
@Autowired
MyNameRemote myNameRemote;
AnnotatedFeignClient annotatedFeignClient;
@Autowired
ArrayListSpanReporter reporter;
@@ -72,29 +72,29 @@ public class ManuallyCreatedLoadBalancerFeignClientTests {
@Test
public void should_reuse_custom_feign_client() {
String response = this.myNameRemote.get();
String response = this.annotatedFeignClient.get();
// then(this.myClient.wasCalled()).isTrue();
then(response).isEqualTo("foo");
List<Span> spans = this.reporter.getSpans();
// retries
then(spans).hasSize(1);
then(spans.get(0).tags().get("http.path")).isEqualTo("");
then(spans.get(0).tags().get("http.path")).isEqualTo("/test");
}
@Test
public void my_client_called() {
this.myNameRemote.get();
this.annotatedFeignClient.get();
then(this.myClient.wasCalled()).isTrue();
}
@Test
public void span_captured() {
this.myNameRemote.get();
this.annotatedFeignClient.get();
List<Span> spans = this.reporter.getSpans();
// retries
then(spans).hasSize(1);
then(spans.get(0).tags().get("http.path")).isEqualTo("");
then(spans.get(0).tags().get("http.path")).isEqualTo("/test");
}
}
@@ -167,9 +167,9 @@ class MyDelegateClient implements Client {
}
@FeignClient(name = "foo", url = "http://foo")
interface MyNameRemote {
interface AnnotatedFeignClient {
@RequestMapping(value = "/", method = RequestMethod.GET)
@RequestMapping(value = "/test", method = RequestMethod.GET)
String get();
}

View File

@@ -63,7 +63,7 @@ public class ManuallyCreatedDelegateLoadBalancerFeignClientTests {
MyDelegateClient myDelegateClient;
@Autowired
MyNameRemote myNameRemote;
AnnotatedFeignClient annotatedFeignClient;
@Autowired
ArrayListSpanReporter reporter;
@@ -78,7 +78,7 @@ public class ManuallyCreatedDelegateLoadBalancerFeignClientTests {
@Test
public void should_reuse_custom_feign_client() {
String response = this.myNameRemote.get();
String response = this.annotatedFeignClient.get();
// then(this.myClient.wasCalled()).isTrue();
then(this.myDelegateClient.wasCalled()).isTrue();
@@ -86,23 +86,23 @@ public class ManuallyCreatedDelegateLoadBalancerFeignClientTests {
List<Span> spans = this.reporter.getSpans();
// retries
then(spans).hasSize(1);
then(spans.get(0).tags().get("http.path")).isEqualTo("");
then(spans.get(0).tags().get("http.path")).isEqualTo("/test");
}
@Test
public void my_client_called() {
this.myNameRemote.get();
this.annotatedFeignClient.get();
then(this.myClient.wasCalled()).isTrue();
then(this.myDelegateClient.wasCalled()).isTrue();
}
@Test
public void span_captured() {
this.myNameRemote.get();
this.annotatedFeignClient.get();
List<Span> spans = this.reporter.getSpans();
// retries
then(spans).hasSize(1);
then(spans.get(0).tags().get("http.path")).isEqualTo("");
then(spans.get(0).tags().get("http.path")).isEqualTo("/test");
}
}
@@ -118,11 +118,11 @@ class Application {
}
@Bean
public MyNameRemote myNameRemote(Client client, Decoder decoder, Encoder encoder,
Contract contract) {
public AnnotatedFeignClient annotatedFeignClient(Client client, Decoder decoder,
Encoder encoder, Contract contract) {
return Feign.builder().client(client).encoder(encoder).decoder(decoder)
.contract(contract)
.target(new HardCodedTarget<>(MyNameRemote.class, "foo", "http://foo"));
.contract(contract).target(new HardCodedTarget<>(
AnnotatedFeignClient.class, "foo", "http://foo"));
}
@Bean
@@ -163,9 +163,9 @@ class MyDelegateClient implements Client {
}
@FeignClient(name = "foo", url = "http://foo")
interface MyNameRemote {
interface AnnotatedFeignClient {
@RequestMapping(value = "/", method = RequestMethod.GET)
@RequestMapping(value = "/test", method = RequestMethod.GET)
String get();
}