Class AsyncReporter<S>
- java.lang.Object
-
- zipkin2.reporter.Component
-
- zipkin2.reporter.AsyncReporter<S>
-
- Type Parameters:
S
- type of the span, usuallySpan
public class AsyncReporter<S> extends Component implements Reporter<S>, Closeable, 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 callsflush()
. 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 BytesMessageSender 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AsyncReporter.Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static AsyncReporter.Builder
builder(BytesMessageSender sender)
Likecreate(BytesMessageSender)
, except you can configure settings such as the timeout.static AsyncReporter.Builder
builder(Sender sender)
Deprecated.Since 3.2, usebuilder(BytesMessageSender)
void
close()
Shuts down the sender thread, and increments drop metrics if there were any unsent spans.static AsyncReporter<zipkin2.Span>
create(BytesMessageSender sender)
Builds a json reporter for Zipkin V2.static AsyncReporter<zipkin2.Span>
create(Sender sender)
Deprecated.Since 3.2, usecreate(BytesMessageSender)
void
flush()
Calling this will flush any pending spans to the transport on the current thread.void
report(S span)
Schedules the span to be sent onto the transport.String
toString()
-
-
-
Method Detail
-
create
@Deprecated public static AsyncReporter<zipkin2.Span> create(Sender sender)
Deprecated.Since 3.2, usecreate(BytesMessageSender)
-
create
public static AsyncReporter<zipkin2.Span> create(BytesMessageSender 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.- Since:
- 3.2
-
builder
@Deprecated public static AsyncReporter.Builder builder(Sender sender)
Deprecated.Since 3.2, usebuilder(BytesMessageSender)
-
builder
public static AsyncReporter.Builder builder(BytesMessageSender sender)
Likecreate(BytesMessageSender)
, except you can configure settings such as the timeout.
-
report
public void report(S span)
Description copied from interface:Reporter
Schedules the span to be sent onto the transport.
-
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 interfaceFlushable
- Throws:
IllegalStateException
- if closed
-
close
public void close()
Shuts down the sender thread, and increments drop metrics if there were any unsent spans.
-
-