Class Sender
- java.lang.Object
-
- zipkin2.reporter.Component
-
- zipkin2.reporter.Sender
-
- All Implemented Interfaces:
Closeable
public abstract class Sender extends Component
Sends a list of encoded spans to a transport such as http or Kafka. Usually, this involves encoding them into a message and enqueueing them for transport over http or Kafka. The typical end recipient is a zipkin collector.Unless mentioned otherwise, senders are not thread-safe. They were designed to be used by a single reporting thread.
Those looking to initialize eagerly should call
Component.check()
. This can be used to reduce latency on the first send operation, or to fail fast.Implementation notes
The parameter is a list of encoded spans as opposed to an encoded message. This allows implementations flexibility on how to encode spans into a message. For example, a large span might need to be sent as a separate message to avoid kafka limits. Also, logging transports like scribe will likely write each span as a separate log line.
This accepts a list of
encoded spans
, as opposed a list of spans likezipkin2.Span
. This allows senders to be re-usable as model shapes change. This also allows them to use their most natural message type. For example, kafka would more naturally send messages as byte arrays.- Since:
- 3.0
-
-
Constructor Summary
Constructors Constructor Description Sender()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract Encoding
encoding()
Returns the encoding this sender requires spans to have.abstract int
messageMaxBytes()
Maximum bytes sendable per message including overhead.int
messageSizeInBytes(int encodedSizeInBytes)
LikemessageSizeInBytes(List)
, except for a single-span.abstract int
messageSizeInBytes(List<byte[]> encodedSpans)
Before invokingsendSpans(List)
, callers must consider message overhead, which might be more than encoding overhead.abstract Call<Void>
sendSpans(List<byte[]> encodedSpans)
Sends a list of encoded spans to a transport such as http or Kafka.
-
-
-
Method Detail
-
encoding
public abstract Encoding encoding()
Returns the encoding this sender requires spans to have.
-
messageMaxBytes
public abstract int messageMaxBytes()
Maximum bytes sendable per message including overhead. This can be calculated usingmessageSizeInBytes(List)
Defaults to 500KB as a conservative default. You may get better or reduced performance by changing this value based on, e.g., machine size or network bandwidth in your infrastructure. Finding a perfect value will require trying out different values in production, but the default should work well enough in most cases.
-
messageSizeInBytes
public abstract int messageSizeInBytes(List<byte[]> encodedSpans)
Before invokingsendSpans(List)
, callers must consider message overhead, which might be more than encoding overhead. This is used to not exceedmessageMaxBytes()
.Note this is not always
Encoding.listSizeInBytes(List)
, as some senders have inefficient list encoding. For example, Scribe base64's then tags each span with a category.
-
messageSizeInBytes
public int messageSizeInBytes(int encodedSizeInBytes)
LikemessageSizeInBytes(List)
, except for a single-span. This is used to ensure a span is never accepted that can never be sent.Always override this, which is only abstract as added after version 2.0
- Parameters:
encodedSizeInBytes
- theencoded size
of a span
-
sendSpans
public abstract Call<Void> sendSpans(List<byte[]> encodedSpans)
Sends a list of encoded spans to a transport such as http or Kafka.- Parameters:
encodedSpans
- list of encoded spans.- Throws:
IllegalStateException
- ifclose
was called.
-
-