ZipkinSpanReporter 无法正常工作
ZipkinSpanReporter is not working properly
我正在尝试评估 zipkin 以便为我们所有的微服务启用分布式跟踪功能。以下是我设置中的版本。
Spring-引导版本:1.5.7.RELEASE
spring-云版:
卡姆登.SR6
zipkin 版本:2.2.1
application.properties
中的 seluth 配置
spring.sleuth.sampler.percentage=1.0
spring.sleuth.web.skipPattern=(^cleanup.|.+favicon.)
然后我创建了 ZipkinSpanReporter bean,如下所示。请注意,我已将 Eureka 服务器设置为所有微服务,甚至是向 Eureka 服务器注册的 zipkin 服务器,以便 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 服务器。报告了一些,几乎所有跨度都被删除了
我已经为
启用了日志记录
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
你能解释一下为什么很多 span 没有报告给 zipkin 服务器吗?
提前致谢。
您的代码很可能已损坏。您可以查看 https://github.com/spring-cloud/spring-cloud-sleuth/blob/master/spring-cloud-sleuth-zipkin/src/main/java/org/springframework/cloud/sleuth/zipkin/ZipkinAutoConfiguration.java class 我们为 Edgware 添加了负载平衡 zipkin 服务器解析的位置。
您使用的是 baeldung 教程中的代码示例是否正确? (http://www.baeldung.com/tracing-services-with-zipkin - 3.2.Spring 配置)
我认为第 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 的人阅读本文并验证和更正代码示例。 ;)
我正在尝试评估 zipkin 以便为我们所有的微服务启用分布式跟踪功能。以下是我设置中的版本。
Spring-引导版本:1.5.7.RELEASE
spring-云版: 卡姆登.SR6
zipkin 版本:2.2.1
中的 seluth 配置application.properties
spring.sleuth.sampler.percentage=1.0
spring.sleuth.web.skipPattern=(^cleanup.|.+favicon.)
然后我创建了 ZipkinSpanReporter bean,如下所示。请注意,我已将 Eureka 服务器设置为所有微服务,甚至是向 Eureka 服务器注册的 zipkin 服务器,以便 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 服务器。报告了一些,几乎所有跨度都被删除了
我已经为
启用了日志记录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
你能解释一下为什么很多 span 没有报告给 zipkin 服务器吗?
提前致谢。
您的代码很可能已损坏。您可以查看 https://github.com/spring-cloud/spring-cloud-sleuth/blob/master/spring-cloud-sleuth-zipkin/src/main/java/org/springframework/cloud/sleuth/zipkin/ZipkinAutoConfiguration.java class 我们为 Edgware 添加了负载平衡 zipkin 服务器解析的位置。
您使用的是 baeldung 教程中的代码示例是否正确? (http://www.baeldung.com/tracing-services-with-zipkin - 3.2.Spring 配置)
我认为第 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 的人阅读本文并验证和更正代码示例。 ;)