Sleuth not reporting client spans with Feign builder
See original GitHub issueFirst if you think this issue would have been better in StackOverflow or other then forgive me and tell it so I’ll know for next time.
Describe the bug When using Feign.builder() to create a BuilderFeign build with ribbon client LoadBalancerFeignClient I notice that the client spans are not sent to zipkin.
I noted the documentation saying ‘nothing created manually will work’ yet I see some instrumentation.
TraceFeignObjectWrapper.wrap
handles LoadBalancerFeignClient
and - from my understanding - TraceLoadBalancerFeignClient
creates a span - that should be sent downstream - and abandon it at the end. On the other hand, for other feign clients, TracingFeignClient
performs the receive.
Given the specific code I suppose there is a rational behind this choice but I do not understand it. Could you explain it?
I managed to have my client reporting client spans by creating a class that extends TraceLoadBalancerFeignClient
and mimic the content of TracingFeignClient
but I’m surprised that this is needed.
Sample A sample app with these classes reproduces the behavior:
public interface BuilderFeign {
@RequestLine("GET /")
String pingGithub();
}
@Configuration
public class BuilderFeignConfig {
@Bean
static BuilderFeign blotterFeignClient(ObjectFactory<HttpMessageConverters> messageConverters,
Client loadBalancerFeignClient){
Request.Options options = new Request.Options(30000, 30000);
return Feign.builder()
.encoder(new SpringEncoder(messageConverters))
.decoder(new SpringDecoder(messageConverters))
.decode404()
.retryer(NEVER_RETRY)
.options(options)
.client(loadBalancerFeignClient)
.target(BuilderFeign.class, "https://api.github.com");
}
@Bean
public Client loadBalancerFeignClient(CachingSpringLoadBalancerFactory cachingFactory,
SpringClientFactory clientFactory, BeanFactory beanFactory,
HttpTracing httpTracing) {
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
cm.setMaxTotal(200);
cm.setDefaultMaxPerRoute(20);
return new LoadBalancerFeignClient(new Client.Default(null, NoopHostnameVerifier.INSTANCE), cachingFactory, clientFactory);
// client spans are reported with this implementation
// return new CustomTraceLoadBalancerFeignClient(httpTracing, new Client.Default(null, NoopHostnameVerifier.INSTANCE), cachingFactory, clientFactory, beanFactory);
}
}
@GetMapping("/builderFeign")
public ResponseEntity<?> getFromBuilderFeign() {
return new ResponseEntity<>(this.builderFeign.pingSgithub(), HttpStatus.OK);
}
My class CustomTraceLoadBalancerFeignClient
is a copy of TracingFeignClient
+ other needed copies (due to closed visibility) except the call to this.delegate.execute(modifiedRequest(request, headers), options)
is replaced by super.execute(modifiedRequest(request, headers), options)
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
My bad. While creating the sample free of corporate stuff I found out I did not test properly earlier. The client spans are now reported correctly with latest versions. Thanks.
Can you create a sample with your code?