Class ZipkinSpanHandler

java.lang.Object
brave.handler.SpanHandler
zipkin2.reporter.brave.ZipkinSpanHandler
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
AsyncZipkinSpanHandler

public class ZipkinSpanHandler
extends brave.handler.SpanHandler
implements Closeable
This allows you to send spans recorded by Brave to a pre-configured Zipkin reporter.

If you can't use AsyncZipkinSpanHandler because you are using an old format, construct the span handler like this:


 reporter = AsyncReporter.builder(URLConnectionSender.create("http://localhost:9411/api/v1/spans"))
                         .build(SpanBytesEncoder.JSON_V1);
 tracingBuilder.addSpanHandler(ZipkinSpanHandler.create(reporter));
 

Note: Use AsyncZipkinSpanHandler if you are using SpanBytesEncoder.JSON_V2 format. This handler has to convert MutableSpan into Span, and that conversion happens inline (during production requests) upon Span.finish() or Span.flush().

Since:
2.13
See Also:
AsyncZipkinSpanHandler, Tracing.Builder.addSpanHandler(SpanHandler)
  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    static class  ZipkinSpanHandler.Builder  

    Nested classes/interfaces inherited from class brave.handler.SpanHandler

    brave.handler.SpanHandler.Cause
  • Field Summary

    Fields inherited from class brave.handler.SpanHandler

    NOOP
  • Method Summary

    Modifier and Type Method Description
    void close()
    Implementations that throw exceptions on close have bugs.
    static brave.handler.SpanHandler create​(Reporter<zipkin2.Span> spanReporter)  
    boolean end​(brave.propagation.TraceContext context, brave.handler.MutableSpan span, brave.handler.SpanHandler.Cause cause)  
    boolean equals​(Object o)
    Overridden to avoid duplicates when added via Tracing.Builder.addSpanHandler(SpanHandler)
    int hashCode()
    Overridden to avoid duplicates when added via Tracing.Builder.addSpanHandler(SpanHandler)
    static ZipkinSpanHandler.Builder newBuilder​(Reporter<zipkin2.Span> spanReporter)  
    ZipkinSpanHandler.Builder toBuilder()
    Allows this instance to be reconfigured, for example ZipkinSpanHandler.Builder.alwaysReportSpans(boolean).
    String toString()  

    Methods inherited from class brave.handler.SpanHandler

    begin, handlesAbandoned

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Method Details

    • create

      public static brave.handler.SpanHandler create​(Reporter<zipkin2.Span> spanReporter)
      Since:
      2.13
    • newBuilder

      public static ZipkinSpanHandler.Builder newBuilder​(Reporter<zipkin2.Span> spanReporter)
      Since:
      2.13
    • toBuilder

      public ZipkinSpanHandler.Builder toBuilder()
      Allows this instance to be reconfigured, for example ZipkinSpanHandler.Builder.alwaysReportSpans(boolean).

      Note: Call close() if you no longer need this instance, as otherwise it can leak resources.

      Since:
      2.15
    • close

      public void close()
      Implementations that throw exceptions on close have bugs. This may result in log warnings, though.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Since:
      2.15
    • end

      public boolean end​(brave.propagation.TraceContext context, brave.handler.MutableSpan span, brave.handler.SpanHandler.Cause cause)
      Overrides:
      end in class brave.handler.SpanHandler
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public final boolean equals​(Object o)
      Overridden to avoid duplicates when added via Tracing.Builder.addSpanHandler(SpanHandler)
      Overrides:
      equals in class Object
    • hashCode

      public final int hashCode()
      Overridden to avoid duplicates when added via Tracing.Builder.addSpanHandler(SpanHandler)
      Overrides:
      hashCode in class Object