如何将opentracing/jaeger与spring cloud、hystrix、feign集成?
Posted
技术标签:
【中文标题】如何将opentracing/jaeger与spring cloud、hystrix、feign集成?【英文标题】:How to integrate opentracing/jaeger with spring cloud, hystrix and feign? 【发布时间】:2019-04-26 10:45:24 【问题描述】:我们最近设置了一个 jaeger 服务器,以便跟踪整个系统中的所有请求。通过简单地将必要的 spring(云)启动器依赖项添加到我们的构建文件中,初始设置工作得非常好。每次,一个请求到达我们的一个服务器时,都会创建一个新的 span 并将其报告给使用一体化 docker 映像设置的 jaeger 服务器。
最重要的依赖如下:
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"
虽然在服务器上创建了 span,但必要的标头不会转发给 feign 客户端。根据文档,添加 opentracing-spring-cloud-feign-starter 依赖项应该可以解决问题,但到目前为止,没有一个 feign 客户端起作用。
我还在 opentracing 提供的自动配置类中添加了一个断点
@Bean
FeignContextBeanPostProcessor feignContextBeanPostProcessor(BeanFactory beanFactory)
return new FeignContextBeanPostProcessor(tracer, beanFactory, spanDecorators);
并在应用程序启动时调用此方法。日志中也有一些关于 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)
我花了很多时间阅读文档并寻找如何正确配置 Spring Boot/Cloud 应用程序以便与 feign 客户端一起工作的示例,但到目前为止我还没有运气。大多数示例使用 Springs 的 RestTemplate 而不是 Feign 客户端。
如果有人能指出我正确的方向,我会非常高兴。
【问题讨论】:
【参考方案1】:在某些情况下,可能需要在 Spring 配置中显式公开 Feign 客户端,以便传播 traceId。这可以通过将以下内容添加到您的配置类之一中轻松完成
@Bean
public Client feignClient()
return new Client.Default(null, null);
【讨论】:
什么Client
适合使用?【参考方案2】:
事实证明 Feign 客户端当前不支持,或者更准确地说,春季开始时不会相应地配置 Feign 客户端。如果您想将 Jaeger 与您的 Feign 客户端一起使用,您必须提供您自己的集成。
根据我目前的经验,jaeger 社区的支持度较低,因此您必须自己获得这些知识,在我看来这是一个很大的缺点,您可能应该考虑使用替代方案。
【讨论】:
我的问题和你一模一样。不支持是什么意思?好像你说启动器应该完成这项工作,所以对我来说这似乎是一个错误!以上是关于如何将opentracing/jaeger与spring cloud、hystrix、feign集成?的主要内容,如果未能解决你的问题,请参考以下文章
Golang微服务:Micro Trace使用opentracing jaeger
Pygame错误:self.spritedict [spr] = surface_blit(spr.image,spr.rect)