Java Brave:.spanReporter() 在 Tracing.newBuilder().localServiceName("service").spanReporter(reporter).build() 中弃用;

Java Brave: .spanReporter() deprecated in Tracing.newBuilder().localServiceName("service").spanReporter(reporter).build();

关于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();

谢谢

如果你看看Tracing.builder (brave 5.13.7)中方法spanReporter的JavaDoc,你就会得到答案:

Deprecated. Since 5.12, use addSpanHandler(SpanHandler) with a ZipkinSpanHandler

Since 5.12, this is deprecated for using ZipkinSpanHandler in the io.zipkin.reporter2:zipkin-reporter-brave library.

For example, here's how to batch send spans via HTTP to a Zipkin-compatible endpoint:

 // 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();