1

Small question regarding Java Brave please.

I have a very small piece of code:

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

The code is working fine, but after a version bump:

 <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>

I am seeing this being deprecated: .spanReporter(reporter)

Looking at the documentation, I am not able to see what is this deprecated in favor of.

May I ask what is the new equivalent of this please?

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

Thank you

Ortomala Lokni
  • 56,620
  • 24
  • 188
  • 240
PatPanda
  • 3,644
  • 9
  • 58
  • 154

1 Answers1

1

If you look at the JavaDoc of the method spanReporter in Tracing.builder (brave 5.13.7), you will have the answer:

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();
Ortomala Lokni
  • 56,620
  • 24
  • 188
  • 240