Class W3CTraceContextPropagator
- java.lang.Object
-
- io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator
-
- All Implemented Interfaces:
TextMapPropagator
@Immutable public final class W3CTraceContextPropagator extends java.lang.Object implements TextMapPropagator
Implementation of the W3C TraceContext propagation protocol. See W3C Trace Context.This is the default propagator for
SpanContext
s. TheSpanContext
type is designed to support all the data propagated via W3C propagation natively.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.List<java.lang.String>
FIELDS
private static W3CTraceContextPropagator
INSTANCE
private static java.util.logging.Logger
logger
private static int
SPAN_ID_HEX_SIZE
private static int
SPAN_ID_OFFSET
private static int
TRACE_ID_HEX_SIZE
private static int
TRACE_ID_OFFSET
private static int
TRACE_OPTION_HEX_SIZE
private static int
TRACE_OPTION_OFFSET
(package private) static java.lang.String
TRACE_PARENT
(package private) static java.lang.String
TRACE_STATE
private static char
TRACEPARENT_DELIMITER
private static int
TRACEPARENT_DELIMITER_SIZE
private static int
TRACEPARENT_HEADER_SIZE
private static java.util.Set<java.lang.String>
VALID_VERSIONS
private static java.lang.String
VERSION
private static java.lang.String
VERSION_00
private static int
VERSION_SIZE
-
Constructor Summary
Constructors Modifier Constructor Description private
W3CTraceContextPropagator()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <C> Context
extract(Context context, C carrier, TextMapGetter<C> getter)
Extracts data from upstream.private static SpanContext
extractContextFromTraceParent(java.lang.String traceparent)
private static <C> SpanContext
extractImpl(C carrier, TextMapGetter<C> getter)
java.util.Collection<java.lang.String>
fields()
The propagation fields defined.static W3CTraceContextPropagator
getInstance()
Returns a singleton instance of aTextMapPropagator
implementing the W3C TraceContext propagation.<C> void
inject(Context context, C carrier, TextMapSetter<C> setter)
Injects data for downstream consumers, for example as HTTP headers.java.lang.String
toString()
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
TRACE_PARENT
static final java.lang.String TRACE_PARENT
- See Also:
- Constant Field Values
-
TRACE_STATE
static final java.lang.String TRACE_STATE
- See Also:
- Constant Field Values
-
FIELDS
private static final java.util.List<java.lang.String> FIELDS
-
VERSION
private static final java.lang.String VERSION
- See Also:
- Constant Field Values
-
VERSION_SIZE
private static final int VERSION_SIZE
- See Also:
- Constant Field Values
-
TRACEPARENT_DELIMITER
private static final char TRACEPARENT_DELIMITER
- See Also:
- Constant Field Values
-
TRACEPARENT_DELIMITER_SIZE
private static final int TRACEPARENT_DELIMITER_SIZE
- See Also:
- Constant Field Values
-
TRACE_ID_HEX_SIZE
private static final int TRACE_ID_HEX_SIZE
-
SPAN_ID_HEX_SIZE
private static final int SPAN_ID_HEX_SIZE
-
TRACE_OPTION_HEX_SIZE
private static final int TRACE_OPTION_HEX_SIZE
-
TRACE_ID_OFFSET
private static final int TRACE_ID_OFFSET
- See Also:
- Constant Field Values
-
SPAN_ID_OFFSET
private static final int SPAN_ID_OFFSET
-
TRACE_OPTION_OFFSET
private static final int TRACE_OPTION_OFFSET
-
TRACEPARENT_HEADER_SIZE
private static final int TRACEPARENT_HEADER_SIZE
-
VALID_VERSIONS
private static final java.util.Set<java.lang.String> VALID_VERSIONS
-
VERSION_00
private static final java.lang.String VERSION_00
- See Also:
- Constant Field Values
-
INSTANCE
private static final W3CTraceContextPropagator INSTANCE
-
-
Method Detail
-
getInstance
public static W3CTraceContextPropagator getInstance()
Returns a singleton instance of aTextMapPropagator
implementing the W3C TraceContext propagation.
-
fields
public java.util.Collection<java.lang.String> fields()
Description copied from interface:TextMapPropagator
The propagation fields defined. If your carrier is reused, you should delete the fields here before callingTextMapPropagator.inject(Context, Object, TextMapSetter)
)}.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.
Some use cases for this are:
- Allow pre-allocation of fields, especially in systems like gRPC Metadata
- Allow a single-pass over an iterator
- Specified by:
fields
in interfaceTextMapPropagator
- Returns:
- the fields that will be used by this formatter.
-
inject
public <C> void inject(Context context, @Nullable C carrier, TextMapSetter<C> setter)
Description copied from interface:TextMapPropagator
Injects data for downstream consumers, for example as HTTP headers. The carrier may be null to facilitate calling this method with a lambda for theTextMapSetter
, in which case that null will be passed to theTextMapSetter
implementation.- Specified by:
inject
in interfaceTextMapPropagator
- Type Parameters:
C
- carrier of propagation fields, such as an http request- Parameters:
context
- theContext
containing the value to be injected.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> Context extract(Context context, @Nullable C carrier, TextMapGetter<C> getter)
Description copied from interface:TextMapPropagator
Extracts data from upstream. For example, from incoming http headers. The returned Context should contain the extracted data, if any, merged with the data from the passed-in Context.If the incoming information could not be parsed, implementations MUST return the original Context, unaltered.
- Specified by:
extract
in interfaceTextMapPropagator
- Type Parameters:
C
- the type of carrier of the propagation fields, such as an http request.- Parameters:
context
- theContext
used to store the extracted value.carrier
- holds propagation fields. For example, an outgoing message or http request.getter
- invoked for each propagation key to get data from the carrier.- Returns:
- the
Context
containing the extracted data.
-
extractImpl
private static <C> SpanContext extractImpl(@Nullable C carrier, TextMapGetter<C> getter)
-
extractContextFromTraceParent
private static SpanContext extractContextFromTraceParent(java.lang.String traceparent)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-