Class AsyncReporter<S>

  • Type Parameters:
    S - type of the span, usually Span
    All Implemented Interfaces:
    Closeable, Flushable, Reporter<S>

    public class AsyncReporter<S>
    extends Component
    implements Reporter<S>, Flushable
    As spans are reported, they are encoded and added to a pending queue. The task of sending spans happens on a separate thread which calls flush(). By doing so, callers are protected from latency or exceptions possible when exporting spans out of process.

    Spans are bundled into messages based on size in bytes or a timeout, whichever happens first.

    The thread that sends flushes spans to the Sender does so in a synchronous loop. This means that even asynchronous transports will wait for an ack before sending a next message. We do this so that a surge of spans doesn't overrun memory or bandwidth via hundreds or thousands of in-flight messages. The downside of this is that reporting is limited in speed to what a single thread can clear. When a thread cannot clear the backlog, new spans are dropped.

    • Method Detail

      • create

        public static AsyncReporter<zipkin2.Span> create​(Sender sender)
        Builds a json reporter for Zipkin V2. If http, the endpoint of the sender is usually "http://zipkinhost:9411/api/v2/spans".

        After a certain threshold, spans are drained and sent to Zipkin collectors.

      • report

        public void report​(S span)
        Description copied from interface: Reporter
        Schedules the span to be sent onto the transport.
        Specified by:
        report in interface Reporter<S>
        Parameters:
        span - Span, should not be null.
      • flush

        public void flush()
        Calling this will flush any pending spans to the transport on the current thread.

        Note: If you set message timeout to zero, you must call this externally as otherwise spans will never be sent.

        Specified by:
        flush in interface Flushable
        Throws:
        IllegalStateException - if closed
      • close

        public void close()
        Shuts down the sender thread, and increments drop metrics if there were any unsent spans.
        Specified by:
        close in interface Closeable
        Overrides:
        close in class Component