public abstract class BinaryPropagationHandler 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 BinaryPropagationHandler binaryPropagationHandler =
Tracing.getBinaryPropagationHandler();
void onSendRequest() {
try (NonThrowingCloseable ss = tracer.spanBuilder("Sent.MyRequest").startScopedSpan()) {
byte[] binaryValue = binaryPropagationHandler.toBinaryValue(
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 BinaryPropagationHandler binaryPropagationHandler =
Tracing.getBinaryPropagationHandler();
void onRequestReceived() {
// Get the binaryValue from the request.
SpanContext spanContext = SpanContext.INVALID;
try {
if (binaryValue != null) {
spanContext = binaryPropagationHandler.fromBinaryValue(binaryValue);
}
} catch (ParseException e) {
// Maybe log the exception.
}
try (NonThrowingCloseable ss =
tracer.spanBuilderWithRemoteParent(spanContext, "Recv.MyRequest").startScopedSpan()) {
// Handle request and send response back.
}
}
| Constructor and Description |
|---|
BinaryPropagationHandler() |
| Modifier and Type | Method and Description |
|---|---|
abstract SpanContext |
fromBinaryValue(byte[] bytes)
Parses the
SpanContext from the binary format. |
abstract byte[] |
toBinaryValue(SpanContext spanContext)
Serializes a
SpanContext using the binary format. |
public abstract byte[] toBinaryValue(SpanContext spanContext)
SpanContext using the binary format.spanContext - the SpanContext to serialize.NullPointerException - if the spanContext is null.public abstract SpanContext fromBinaryValue(byte[] bytes) throws ParseException
SpanContext from 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 invalid