Class PassThroughPropagator
- java.lang.Object
-
- io.opentelemetry.api.incubator.propagation.PassThroughPropagator
-
- All Implemented Interfaces:
TextMapPropagator
public final class PassThroughPropagator extends java.lang.Object implements TextMapPropagator
ATextMapPropagator
which can be configured with a set of fields, which will be extracted and stored inContext
. If theContext
is used again to inject, the values will be injected as-is. ThisTextMapPropagator
is appropriate for a service that does not need to participate in telemetry in any way and provides the most efficient way of propagating incoming context to outgoing requests. In almost all cases, you will configure this singleTextMapPropagator
when usingOpenTelemetry.propagating(ContextPropagators)
to create anOpenTelemetry
that only propagates. Similarly, you will never need this when using the OpenTelemetry SDK to enable telemetry.
-
-
Field Summary
Fields Modifier and Type Field Description private static ContextKey<java.util.List<java.lang.String>>
EXTRACTED_KEY_VALUES
private java.util.List<java.lang.String>
fields
-
Constructor Summary
Constructors Modifier Constructor Description private
PassThroughPropagator(java.util.List<java.lang.String> fields)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static TextMapPropagator
create(java.lang.Iterable<java.lang.String> fields)
Returns aTextMapPropagator
which will propagate the givenfields
from extraction to injection.static TextMapPropagator
create(java.lang.String... fields)
Returns aTextMapPropagator
which will propagate the givenfields
from extraction to injection.<C> Context
extract(Context context, C carrier, TextMapGetter<C> getter)
Extracts data from upstream.java.util.Collection<java.lang.String>
fields()
The propagation fields defined.<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
-
EXTRACTED_KEY_VALUES
private static final ContextKey<java.util.List<java.lang.String>> EXTRACTED_KEY_VALUES
-
fields
private final java.util.List<java.lang.String> fields
-
-
Method Detail
-
create
public static TextMapPropagator create(java.lang.String... fields)
Returns aTextMapPropagator
which will propagate the givenfields
from extraction to injection.
-
create
public static TextMapPropagator create(java.lang.Iterable<java.lang.String> fields)
Returns aTextMapPropagator
which will propagate the givenfields
from extraction to injection.
-
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.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-