Class W3CBaggagePropagator
- java.lang.Object
-
- io.opentelemetry.api.baggage.propagation.W3CBaggagePropagator
-
- All Implemented Interfaces:
TextMapPropagator
public final class W3CBaggagePropagator extends java.lang.Object implements TextMapPropagator
TextMapPropagator
that implements the W3C specification for baggage header propagation.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
FIELD
private static java.util.List<java.lang.String>
FIELDS
private static W3CBaggagePropagator
INSTANCE
private static PercentEscaper
URL_ESCAPER
-
Constructor Summary
Constructors Modifier Constructor Description private
W3CBaggagePropagator()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static boolean
baggageIsInvalid(java.lang.String key, BaggageEntry baggageEntry)
private static java.lang.String
baggageToString(Baggage baggage)
private static java.lang.String
encodeValue(java.lang.String value)
<C> Context
extract(Context context, C carrier, TextMapGetter<C> getter)
Extracts data from upstream.private static void
extractEntries(java.lang.String baggageHeader, BaggageBuilder baggageBuilder)
java.util.Collection<java.lang.String>
fields()
The propagation fields defined.static W3CBaggagePropagator
getInstance()
Singleton instance of the W3C Baggage Propagator.<C> void
inject(Context context, C carrier, TextMapSetter<C> setter)
Injects data for downstream consumers, for example as HTTP headers.private static boolean
isValidBaggageKey(java.lang.String name)
Determines whether the givenString
is a valid entry key.private static boolean
isValidBaggageValue(java.lang.String value)
Determines whether the givenString
is a valid entry value.java.lang.String
toString()
-
-
-
Field Detail
-
FIELD
private static final java.lang.String FIELD
- See Also:
- Constant Field Values
-
FIELDS
private static final java.util.List<java.lang.String> FIELDS
-
INSTANCE
private static final W3CBaggagePropagator INSTANCE
-
URL_ESCAPER
private static final PercentEscaper URL_ESCAPER
-
-
Method Detail
-
getInstance
public static W3CBaggagePropagator getInstance()
Singleton instance of the W3C Baggage Propagator.
-
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.
-
baggageToString
private static java.lang.String baggageToString(Baggage baggage)
-
encodeValue
private static java.lang.String encodeValue(java.lang.String value)
-
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.
-
extractEntries
private static void extractEntries(java.lang.String baggageHeader, BaggageBuilder baggageBuilder)
-
baggageIsInvalid
private static boolean baggageIsInvalid(java.lang.String key, BaggageEntry baggageEntry)
-
isValidBaggageKey
private static boolean isValidBaggageKey(java.lang.String name)
Determines whether the givenString
is a valid entry key.- Parameters:
name
- the entry key name to be validated.- Returns:
- whether the name is valid.
-
isValidBaggageValue
private static boolean isValidBaggageValue(java.lang.String value)
Determines whether the givenString
is a valid entry value.- Parameters:
value
- the entry value to be validated.- Returns:
- whether the value is valid.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-