关于Java勇敢的小问题。
我有一个非常小的代码:
OkHttpSender sender = OkHttpSender.newBuilder().endpoint("https://zipkin-instance.com:9411/api/v2/spans").build();
AsyncReporter<Span> reporter = AsyncReporter.builder(sender).build();
Tracing tracing = Tracing.newBuilder().localServiceName("service").spanReporter(reporter).build();代码运行良好,但在版本增加之后:
<dependency>
<groupId>io.opentracing.brave</groupId>
<artifactId>brave-opentracing</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-sender-okhttp3</artifactId>
<version>2.16.3</version>
</dependency>我看到有人反对这样做:.spanReporter(reporter)
看一下文档,我看不出有什么不可取之处。
请问这个新的等价物是什么?
OkHttpSender sender = OkHttpSender.newBuilder().endpoint("https://zipkin-instance.com:9411/api/v2/spans").build();
AsyncReporter<Span> reporter = AsyncReporter.builder(sender).build();
Tracing tracing = Tracing.newBuilder().localServiceName("service").spanReporter(reporter).build();谢谢
发布于 2022-02-27 14:20:32
如果您查看方法的JavaDoc ( spanReporter in Tracing.builder (勇敢5.13.7) ),您将得到答案:
不赞成。从5.12开始,将addSpanHandler(SpanHandler)与ZipkinSpanHandler一起使用 从5.12开始,这里就不推荐在io.zipkin.recter2:zipkin-reporter库中使用ZipkinSpanHandler。 例如,下面是如何通过HTTP将spans批处理发送到与Zipkin兼容的端点:
// Configure a reporter, which controls how often spans are sent
// (this dependency is io.zipkin.reporter2:zipkin-sender-okhttp3)
sender = OkHttpSender.create("http://127.0.0.1:9411/api/v2/spans");
// (this dependency is io.zipkin.reporter2:zipkin-reporter-brave)
zipkinSpanHandler = AsyncZipkinSpanHandler.create(sender); // don't forget to close!
// Create a tracing component with the service name you want to see in Zipkin.
tracing = Tracing.newBuilder()
.localServiceName("my-service")
.addSpanHandler(zipkinSpanHandler)
.build();https://stackoverflow.com/questions/69549526
复制相似问题