我正在尝试将 Brave MySql Instrumentation 集成到我的 Spring Boot 2.x 服务中,以自动让它的拦截器使用有关 MySql-Queries 的跨度来丰富我的跟踪。
当前的 Gradle-Dependencies 如下
compile 'io.zipkin.zipkin2:zipkin:2.4.5'
compile('io.zipkin.reporter2:zipkin-sender-okhttp3:2.3.1')
compile('io.zipkin.brave:brave-instrumentation-mysql:4.14.3')
compile('org.springframework.cloud:spring-cloud-starter-zipkin:2.0.0.M5')
我已经成功配置了 Sleuth 以将有关 HTTP-Request 的跟踪发送到我的 Zipkin-Server,现在我想为该服务所做的每个 MySql-Query 添加一些跨度。
TracingConfiguration 它是这样的:
@Configuration
public class TracingConfiguration {
/** Configuration for how to send spans to Zipkin */
@Bean
Sender sender() {
return OkHttpSender.create("https://myzipkinserver.com/api/v2/spans");
}
/** Configuration for how to buffer spans into messages for Zipkin */
@Bean AsyncReporter<Span> spanReporter() {
return AsyncReporter.create(sender());
}
@Bean Tracing tracing(Reporter<Span> spanListener) {
return Tracing.newBuilder()
.spanReporter(spanReporter())
.build();
}
}
查询拦截器工作正常,但我现在的问题是跨度没有添加到现有跟踪中,而是每个都添加到新的跟踪中。
我猜这是因为在配置中创建了一个新的发送者/报告者,但我无法重用由 Spring Boot Autoconfiguration 创建的现有发送者/报告者。此外,这将消除冗余定义 Zipkin-Url 的必要性(因为它已经在我的 application.yml 中为 Zipkin 定义)。
我已经尝试将 Zipkin-Reporter 自动连接到我的 Bean,但我得到的只是一个SpanReporter
- 但 Brave-Tracer-Builder 需要一个Reporter<Span>
你对我如何正确接线有什么建议吗?