Package io.opencensus.contrib.http.util
Class CloudTraceFormat
java.lang.Object
io.opencensus.trace.propagation.TextFormat
io.opencensus.contrib.http.util.CloudTraceFormat
Implementation of the "X-Cloud-Trace-Context" format, defined by the Google Cloud Trace.
The supported format is the following:
<TRACE_ID>/<SPAN_ID>[;o=<TRACE_OPTIONS>]
- TRACE_ID is a 32-character hex value;
- SPAN_ID is a decimal representation of a 64-bit unsigned long;
- TRACE_OPTIONS is a decimal representation of a 32-bit unsigned integer. The least significant bit defines whether a request is traced (1 - enabled, 0 - disabled). Behaviors of other bits are currently undefined. This value is optional. Although upstream service may leave this value unset to leave the sampling decision up to downstream client, this utility will always default it to 0 if absent.
Valid values:
- "105445aa7843bc8bf206b120001000/123;o=1"
- "105445aa7843bc8bf206b120001000/123"
- "105445aa7843bc8bf206b120001000/123;o=0"
-
Nested Class Summary
Nested classes/interfaces inherited from class io.opencensus.trace.propagation.TextFormat
TextFormat.Getter<C>, TextFormat.Setter<C>
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final int
(package private) static final String
(package private) static final int
(package private) static final String
(package private) static final TraceOptions
(package private) static final TraceOptions
(package private) static final String
(package private) static final char
(package private) static final int
(package private) static final int
(package private) static final String
(package private) static final int
private static final Tracestate
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<C> SpanContext
extract
(C carrier, TextFormat.Getter<C> getter) Extracts the span context from upstream.fields()
The propagation fields defined.<C> void
inject
(SpanContext spanContext, C carrier, TextFormat.Setter<C> setter) Injects the span context downstream.private static SpanId
longToSpanId
(long x) private static long
spanIdToLong
(SpanId spanId)
-
Field Details
-
HEADER_NAME
- See Also:
-
FIELDS
-
SPAN_ID_DELIMITER
static final char SPAN_ID_DELIMITER- See Also:
-
TRACE_OPTION_DELIMITER
- See Also:
-
SAMPLED
- See Also:
-
NOT_SAMPLED
- See Also:
-
OPTIONS_SAMPLED
-
OPTIONS_NOT_SAMPLED
-
TRACE_ID_SIZE
static final int TRACE_ID_SIZE- See Also:
-
TRACE_OPTION_DELIMITER_SIZE
static final int TRACE_OPTION_DELIMITER_SIZE -
SPAN_ID_START_POS
static final int SPAN_ID_START_POS- See Also:
-
MIN_HEADER_SIZE
static final int MIN_HEADER_SIZE- See Also:
-
CLOUD_TRACE_IS_SAMPLED
static final int CLOUD_TRACE_IS_SAMPLED- See Also:
-
TRACESTATE_DEFAULT
-
-
Constructor Details
-
CloudTraceFormat
CloudTraceFormat()
-
-
Method Details
-
fields
Description copied from class:TextFormat
The propagation fields defined. If your carrier is reused, you should delete the fields here before callingTextFormat.inject(SpanContext, Object, Setter)
.For example, if the carrier is a single-use or immutable request object, you don't need to clear fields as they couldn't have been set before. If it is a mutable, retryable object, successive calls should clear these fields first.
- Specified by:
fields
in classTextFormat
-
inject
Description copied from class:TextFormat
Injects the span context downstream. For example, as http headers.- Specified by:
inject
in classTextFormat
- Parameters:
spanContext
- possibly not sampled.carrier
- holds propagation fields. For example, an outgoing message or http request.setter
- invoked for each propagation key to add or remove.
-
extract
public <C> SpanContext extract(C carrier, TextFormat.Getter<C> getter) throws SpanContextParseException Description copied from class:TextFormat
Extracts the span context from upstream. For example, as http headers.- Specified by:
extract
in classTextFormat
- Parameters:
carrier
- holds propagation fields. For example, an outgoing message or http request.getter
- invoked for each propagation key to get.- Throws:
SpanContextParseException
- if the input is invalid
-
longToSpanId
-
spanIdToLong
-