ZipkinSpanReporter无法正常工作

时间:2017-10-30 05:15:24

标签: spring-cloud-netflix zipkin spring-cloud-sleuth

我正在尝试评估zipkin,以便为我们所有的微服务启用分布式跟踪功能。以下是我的设置中的版本。

  1. Spring-boot版本: 1.5.7.RELEASE
  2. spring-cloud版本: Camden.SR6
  3. zipkin版本: 2.2.1

    application.properties

  4. 中的seluth配置

    spring.sleuth.sampler.percentage = 1.0

    spring.sleuth.web.skipPattern =(^清理 |。。。+图标

    我创建了ZipkinSpanReporter bean,如下所示。请注意,我已经将Eureka服务器设置为所有微服务甚至zipkin服务器注册了Eureka服务器,以便Zipkin客户端可以通过eureka解析zipkin服务器

     @Bean
        public ZipkinSpanReporter makeZipkinSpanReporter() {
            return new ZipkinSpanReporter() {
                private HttpZipkinSpanReporter delegate;
                private String baseUrl;
    
                @Override
                public void report(Span span) {
    
                    InstanceInfo instance = eurekaClient
                            .getNextServerFromEureka("zipkin", false);
                    if (!(baseUrl != null &&
                            instance.getHomePageUrl().equals(baseUrl))) {
                        baseUrl = instance.getHomePageUrl();
                        delegate = new HttpZipkinSpanReporter(baseUrl,
                                zipkinProperties.getFlushInterval(),
                                zipkinProperties.getCompression().isEnabled(),
                                spanMetricReporter);
    
                        if (!span.name.matches(skipPattern)) delegate.report(span);
                    }
                }
            };
        }
    

    我观察到的是,当我检查zipkin时,zipkin客户端(书)没有将所有跨度报告回zipkin服务器。据报道,几乎有一些跨度掉落

    enter image description here

    我已启用日志记录

    logging.level.org.springframework.cloud.sleuth.instrument.web=DEBUG
    logging.file=book.log
    

    以下是日志信息:

    2017-10-30 12:51:41.747 DEBUG [book,73fdabf29eb273f2,73fdabf29eb273f2,true] 14088 --- [http-nio-8888-exec-1] o.s.c.sleuth.instrument.web.TraceFilter  : No parent span present - creating a new span
    2017-10-30 12:51:41.749 DEBUG [book,73fdabf29eb273f2,73fdabf29eb273f2,true] 14088 --- [http-nio-8888-exec-1] o.s.c.s.i.web.TraceHandlerInterceptor    : Handling span [Trace: 73fdabf29eb273f2, Span: 73fdabf29eb273f2, Parent: null, exportable:true]
    2017-10-30 12:51:41.750 DEBUG [book,73fdabf29eb273f2,73fdabf29eb273f2,true] 14088 --- [http-nio-8888-exec-1] o.s.c.s.i.web.TraceHandlerInterceptor    : Adding a method tag with value [checkedOut] to a span [Trace: 73fdabf29eb273f2, Span: 73fdabf29eb273f2, Parent: null, exportable:true]
    2017-10-30 12:51:41.750 DEBUG [book,73fdabf29eb273f2,73fdabf29eb273f2,true] 14088 --- [http-nio-8888-exec-1] o.s.c.s.i.web.TraceHandlerInterceptor    : Adding a class tag with value [BookApplication] to a span [Trace: 73fdabf29eb273f2, Span: 73fdabf29eb273f2, Parent: null, exportable:true]
    2017-10-30 12:51:41.752 DEBUG [book,73fdabf29eb273f2,73fdabf29eb273f2,true] 14088 --- [http-nio-8888-exec-1] o.s.c.sleuth.instrument.web.TraceFilter  : Closing the span [Trace: 73fdabf29eb273f2, Span: 73fdabf29eb273f2, Parent: null, exportable:true] since the response was successful
    2017-10-30 12:51:42.133 DEBUG [book,,,] 14088 --- [http-nio-8888-exec-1] o.s.c.sleuth.instrument.web.TraceFilter  : Received a request to uri [/favicon.ico] that should not be sampled [true]
    2017-10-30 12:51:42.134 DEBUG [book,9e7aab2fdb2313a9,9e7aab2fdb2313a9,false] 14088 --- [http-nio-8888-exec-1] o.s.c.sleuth.instrument.web.TraceFilter  : No parent span present - creating a new span
    2017-10-30 12:51:42.142 DEBUG [book,9e7aab2fdb2313a9,9e7aab2fdb2313a9,false] 14088 --- [http-nio-8888-exec-1] o.s.c.sleuth.instrument.web.TraceFilter  : Closing the span [Trace: 9e7aab2fdb2313a9, Span: 9e7aab2fdb2313a9, Parent: null, exportable:false] since the response was successful
    2017-10-30 12:52:05.167 DEBUG [book,,,] 14088 --- [http-nio-8888-exec-2] o.s.c.sleuth.instrument.web.TraceFilter  : Received a request to uri [/checked-out] that should not be sampled [false]
    2017-10-30 12:52:05.168 DEBUG [book,05274e0bdf3038b9,05274e0bdf3038b9,true] 14088 --- [http-nio-8888-exec-2] o.s.c.sleuth.instrument.web.TraceFilter  : No parent span present - creating a new span
    2017-10-30 12:52:05.171 DEBUG [book,05274e0bdf3038b9,05274e0bdf3038b9,true] 14088 --- [http-nio-8888-exec-2] o.s.c.s.i.web.TraceHandlerInterceptor    : Handling span [Trace: 05274e0bdf3038b9, Span: 05274e0bdf3038b9, Parent: null, exportable:true]
    2017-10-30 12:52:05.171 DEBUG [book,05274e0bdf3038b9,05274e0bdf3038b9,true] 14088 --- [http-nio-8888-exec-2] o.s.c.s.i.web.TraceHandlerInterceptor    : Adding a method tag with value [checkedOut] to a span [Trace: 05274e0bdf3038b9, Span: 05274e0bdf3038b9, Parent: null, exportable:true]
    2017-10-30 12:52:05.172 DEBUG [book,05274e0bdf3038b9,05274e0bdf3038b9,true] 14088 --- [http-nio-8888-exec-2] o.s.c.s.i.web.TraceHandlerInterceptor    : Adding a class tag with value [BookApplication] to a span [Trace: 05274e0bdf3038b9, Span: 05274e0bdf3038b9, Parent: null, exportable:true]
    2017-10-30 12:52:05.174 DEBUG [book,05274e0bdf3038b9,05274e0bdf3038b9,true] 14088 --- [http-nio-8888-exec-2] o.s.c.sleuth.instrument.web.TraceFilter  : Closing the span [Trace: 05274e0bdf3038b9, Span: 05274e0bdf3038b9, Parent: null, exportable:true] since the response was successful
    2017-10-30 12:52:05.589 DEBUG [book,,,] 14088 --- [http-nio-8888-exec-2] o.s.c.sleuth.instrument.web.TraceFilter  : Received a request to uri [/favicon.ico] that should not be sampled [true]
    2017-10-30 12:52:05.589 DEBUG [book,b891d03ce6bccdf4,b891d03ce6bccdf4,false] 14088 --- [http-nio-8888-exec-2] o.s.c.sleuth.instrument.web.TraceFilter  : No parent span present - creating a new span
    2017-10-30 12:52:05.594 DEBUG [book,b891d03ce6bccdf4,b891d03ce6bccdf4,false] 14088 --- [http-nio-8888-exec-2] o.s.c.sleuth.instrument.web.TraceFilter  : Closing the span [Trace: b891d03ce6bccdf4, Span: b891d03ce6bccdf4, Parent: null, exportable:false] since the response was successful
    

    但是我找不到从zipkin控制台登录book.log文件的traceId

    请问您解释为什么没有向zipkin服务器报告多个跨度?

    提前致谢。

2 个答案:

答案 0 :(得分:2)

很可能你的代码被破坏了。您可以查看https://github.com/spring-cloud/spring-cloud-sleuth/blob/master/spring-cloud-sleuth-zipkin/src/main/java/org/springframework/cloud/sleuth/zipkin/ZipkinAutoConfiguration.java课程,了解Edgware我们已经添加了负载均衡的zipkin服务器分辨率。

答案 1 :(得分:0)

使用baeldung教程中的代码示例是否正确? (http://www.baeldung.com/tracing-services-with-zipkin - 3.2.Spring Config)

我认为第34和35行(结束大括号)有一个错误。

我通过修改这样的方法解决了这个问题:

@Bean
public ZipkinSpanReporter makeZipkinSpanReporter() {
    return new ZipkinSpanReporter() {
        private HttpZipkinSpanReporter delegate;
        private String baseUrl;

        @Override
        public void report(Span span) {

            InstanceInfo instance = eurekaClient
                    .getNextServerFromEureka("zipkin", false);
            if (!(baseUrl != null &&
                    instance.getHomePageUrl().equals(baseUrl))) {
                baseUrl = instance.getHomePageUrl();
                RestTemplate restTemplate = new RestTemplate();
                zipkinRestTemplateCustomizer.customize(restTemplate);
                delegate = new HttpZipkinSpanReporter(
                        restTemplate,
                        baseUrl,
                        zipkinProperties.getFlushInterval(),
                        spanMetricReporter);
            }

            if (!span.name.matches(skipPattern)) {
                delegate.report(span);
            }
        }
    };
}

也许这有助于某人或baeldung的某人阅读此内容,并可以验证并更正代码示例。 ;)