public abstract class BinaryFormat extends Object
SpanContext
propagation on the wire using binary encoding.
Example of usage on the client:
private static final Tracer tracer = Tracing.getTracer();
private static final BinaryFormat binaryFormat =
Tracing.getPropagationComponent().getBinaryFormat();
void onSendRequest() {
try (Scope ss = tracer.spanBuilder("Sent.MyRequest").startScopedSpan()) {
byte[] binaryValue = binaryFormat.toByteArray(tracer.getCurrentContext().context());
// Send the request including the binaryValue and wait for the response.
}
}
Example of usage on the server:
private static final Tracer tracer = Tracing.getTracer();
private static final BinaryFormat binaryFormat =
Tracing.getPropagationComponent().getBinaryFormat();
void onRequestReceived() {
// Get the binaryValue from the request.
SpanContext spanContext = SpanContext.INVALID;
try {
if (binaryValue != null) {
spanContext = binaryFormat.fromByteArray(binaryValue);
}
} catch (SpanContextParseException e) {
// Maybe log the exception.
}
try (Scope ss =
tracer.spanBuilderWithRemoteParent("Recv.MyRequest", spanContext).startScopedSpan()) {
// Handle request and send response back.
}
}
Constructor and Description |
---|
BinaryFormat() |
Modifier and Type | Method and Description |
---|---|
SpanContext |
fromBinaryValue(byte[] bytes)
Deprecated.
|
SpanContext |
fromByteArray(byte[] bytes)
Parses the
SpanContext from a byte array using the binary format. |
byte[] |
toBinaryValue(SpanContext spanContext)
Deprecated.
|
byte[] |
toByteArray(SpanContext spanContext)
Serializes a
SpanContext into a byte array using the binary format. |
@Deprecated public byte[] toBinaryValue(SpanContext spanContext)
toByteArray(SpanContext)
.SpanContext
into a byte array using the binary format.spanContext
- the SpanContext
to serialize.NullPointerException
- if the spanContext
is null
.public byte[] toByteArray(SpanContext spanContext)
SpanContext
into a byte array using the binary format.spanContext
- the SpanContext
to serialize.NullPointerException
- if the spanContext
is null
.@Deprecated public SpanContext fromBinaryValue(byte[] bytes) throws ParseException
fromByteArray(byte[])
.SpanContext
from a byte array using the binary format.bytes
- a binary encoded buffer from which the SpanContext
will be parsed.SpanContext
.NullPointerException
- if the input
is null
.ParseException
- if the version is not supported or the input is invalidpublic SpanContext fromByteArray(byte[] bytes) throws SpanContextParseException
SpanContext
from a byte array using the binary format.bytes
- a binary encoded buffer from which the SpanContext
will be parsed.SpanContext
.NullPointerException
- if the input
is null
.SpanContextParseException
- if the version is not supported or the input is invalid