Search code examples
spring-boothystrixfeignopentracingjaeger

How to integrate opentracing/jaeger with spring cloud, hystrix and feign?


We lately setup a jaeger server in order to trace all requests throughout our system. The initial setup worked pretty nicely by simply adding the necessary spring (cloud) starter dependencies to our build files. Each time, a request hits one of our servers, a new span is created and reported to the jaeger server which was setup by using the all-in-one docker image.

The most important dependencies are the following:

compile "org.springframework.boot:spring-boot-starter-web"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-undertow"
compile "org.springframework.boot:spring-boot-starter-aop"

compile "org.springframework.cloud:spring-cloud-starter-netflix-hystrix:2.0.2.RELEASE"
compile "org.springframework.cloud:spring-cloud-starter-openfeign:2.0.2.RELEASE"

compile "io.opentracing.contrib:opentracing-spring-cloud-feign-starter:0.2.1"
compile "io.opentracing.contrib:opentracing-spring-jaeger-cloud-starter:0.2.1"
compile "io.opentracing.contrib:opentracing-spring-jaeger-starter:0.2.1"
compile "io.opentracing.contrib:opentracing-spring-web-autoconfigure:0.2.1"

While spans are created on the server, the necessary headers are not forwarded to the feign clients. According to the documentation, the addition of opentracing-spring-cloud-feign-starter dependency should to the trick, but so far, none of the feign clients worked.

I also added a breakpoint to the auto configure class provided by opentracing

@Bean
FeignContextBeanPostProcessor feignContextBeanPostProcessor(BeanFactory beanFactory) {
    return new FeignContextBeanPostProcessor(tracer, beanFactory, spanDecorators);
}

and this method is invoked, when the application starts up. There are also is also some information in the logs regarding the initialization of jaeger/opentracing:

main 22:26:53.371 3222 INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'io.opentracing.contrib.spring.cloud.async.DefaultAsyncAutoConfiguration$DefaultTracedAsyncConfigurerSupport' of type [io.opentracing.contrib.spring.cloud.async.DefaultAsyncAutoConfiguration$DefaultTracedAsyncConfigurerSupport$$EnhancerBySpringCGLIB$$4ab0858a] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
main 22:26:53.478 3329 INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'io.opentracing.contrib.spring.cloud.async.DefaultAsyncAutoConfiguration' of type [io.opentracing.contrib.spring.cloud.async.DefaultAsyncAutoConfiguration$$EnhancerBySpringCGLIB$$4bce5627] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
main 22:26:53.670 3521 INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'io.opentracing.contrib.spring.cloud.feign.FeignTracingAutoConfiguration' of type [io.opentracing.contrib.spring.cloud.feign.FeignTracingAutoConfiguration$$EnhancerBySpringCGLIB$$3a2361a6] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
main 22:26:53.905 3756 INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'io.opentracing.contrib.java.spring.jaeger.starter.JaegerAutoConfiguration' of type [io.opentracing.contrib.java.spring.jaeger.starter.JaegerAutoConfiguration$$EnhancerBySpringCGLIB$$5c956416] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
main 22:26:53.942 3793 INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'opentracing.jaeger-io.opentracing.contrib.java.spring.jaeger.starter.JaegerConfigurationProperties' of type [io.opentracing.contrib.java.spring.jaeger.starter.JaegerConfigurationProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
main 22:26:53.962 3813 INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'metricsFactory' of type [io.jaegertracing.internal.metrics.NoopMetricsFactory] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
main 22:26:53.977 3828 INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'reporterMetrics' of type [io.jaegertracing.internal.metrics.Metrics] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
main 22:26:53.982 3833 INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'sampler' of type [io.jaegertracing.internal.samplers.ConstSampler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
main 22:26:54.013 3864 INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'reporter' of type [io.jaegertracing.internal.reporters.CompositeReporter] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
main 22:26:54.028 3879 INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'tracer' of type [io.jaegertracing.internal.JaegerTracer] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
main 22:26:59.495 9346 INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$216245cc] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

I spent quite some time, reading into documentation and looking for examples how to configure a spring boot/cloud application correctly in order to work with feign clients but so far I had no luck. Most examples out there use Springs' RestTemplate instead of Feign clients.

I would be very happy, if somebody could point me towards the right direction.


Solution

  • Turns out that Feign clients are currently not supported or to be precise, the spring startes do not configure the Feign clients accordingly. If you want to use Jaeger with your Feign clients, you have to provide an integration of your own.

    In my experience so far, the jaeger community is a lesser supportive one, thus you have to gain such knowledge on your own, which in my opinion is a big downside and you should probably consider, using an alternative.