Package io.opencensus.contrib.http.util
Class CloudTraceFormat
- java.lang.Object
-
- io.opencensus.trace.propagation.TextFormat
-
- io.opencensus.contrib.http.util.CloudTraceFormat
-
final class CloudTraceFormat extends TextFormat
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
Fields Modifier and Type Field Description (package private) static int
CLOUD_TRACE_IS_SAMPLED
(package private) static java.util.List<java.lang.String>
FIELDS
(package private) static java.lang.String
HEADER_NAME
(package private) static int
MIN_HEADER_SIZE
(package private) static java.lang.String
NOT_SAMPLED
(package private) static TraceOptions
OPTIONS_NOT_SAMPLED
(package private) static TraceOptions
OPTIONS_SAMPLED
(package private) static java.lang.String
SAMPLED
(package private) static char
SPAN_ID_DELIMITER
(package private) static int
SPAN_ID_START_POS
(package private) static int
TRACE_ID_SIZE
(package private) static java.lang.String
TRACE_OPTION_DELIMITER
(package private) static int
TRACE_OPTION_DELIMITER_SIZE
private static Tracestate
TRACESTATE_DEFAULT
-
Constructor Summary
Constructors Constructor Description CloudTraceFormat()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <C> SpanContext
extract(C carrier, TextFormat.Getter<C> getter)
Extracts the span context from upstream.java.util.List<java.lang.String>
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 Detail
-
HEADER_NAME
static final java.lang.String HEADER_NAME
- See Also:
- Constant Field Values
-
FIELDS
static final java.util.List<java.lang.String> FIELDS
-
SPAN_ID_DELIMITER
static final char SPAN_ID_DELIMITER
- See Also:
- Constant Field Values
-
TRACE_OPTION_DELIMITER
static final java.lang.String TRACE_OPTION_DELIMITER
- See Also:
- Constant Field Values
-
SAMPLED
static final java.lang.String SAMPLED
- See Also:
- Constant Field Values
-
NOT_SAMPLED
static final java.lang.String NOT_SAMPLED
- See Also:
- Constant Field Values
-
OPTIONS_SAMPLED
static final TraceOptions OPTIONS_SAMPLED
-
OPTIONS_NOT_SAMPLED
static final TraceOptions OPTIONS_NOT_SAMPLED
-
TRACE_ID_SIZE
static final int TRACE_ID_SIZE
- See Also:
- Constant Field Values
-
TRACE_OPTION_DELIMITER_SIZE
static final int TRACE_OPTION_DELIMITER_SIZE
-
SPAN_ID_START_POS
static final int SPAN_ID_START_POS
- See Also:
- Constant Field Values
-
MIN_HEADER_SIZE
static final int MIN_HEADER_SIZE
- See Also:
- Constant Field Values
-
CLOUD_TRACE_IS_SAMPLED
static final int CLOUD_TRACE_IS_SAMPLED
- See Also:
- Constant Field Values
-
TRACESTATE_DEFAULT
private static final Tracestate TRACESTATE_DEFAULT
-
-
Method Detail
-
fields
public java.util.List<java.lang.String> 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
public <C> void inject(SpanContext spanContext, C carrier, TextFormat.Setter<C> setter)
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
private static SpanId longToSpanId(long x)
-
spanIdToLong
private static long spanIdToLong(SpanId spanId)
-
-