otel_propagator_text_map behaviour (OpenTelemetry API v1.4.0)
View SourceA TextMap Propagator is a Propagator that performs injection and extraction with ASCII keys and values.
An example of configuring the TextMap Propagator to inject and extract Baggage and TraceContext:
{text_map_propagators, [trace_context, baggage]},
The propagators are then used at the points that cross-service communication is performed. By default, inject/2
and extract/2
work on a generic list of 2-tuple's with binary string keys and values. You can pass (as an argument) a user-defined function for setting a key/value in the carrier and for getting the value of a key. For example, injecting and extracting to and from Hackney headers could be done with Hackney-specific functions:
set_header(Key, Value, Headers) ->
hackney_headers:store(Key, Value, Headers).
some_fun_calling_hackney() ->
Headers = otel_propagator_text_map:inject(opentelemetry:get_text_map_injector(), hackney_headers:new(), fun set_header/2),
%% ...
An example of extraction in an Elli request handler:
get_header(Req, Key) ->
elli_request:get_header(Key, Req, Default).
handle(Req, _Args) ->
otel_propagator_text_map:extract(Req, fun get_header/2),
%% ...
{ok, [], <<"hello world">>}.
Summary
Functions
Extracts the current context from the provided Carrier
using the current TextMap Propagator.
Extracts the current context from the provided Carrier
using the given Propagator
.
Extracts the current context from the provided Carrier
using the given Propagator
and functions to get all the keys and get the keys from the carrier.
Extracts the current context from the provided Carrier
using the given Propagator
and functions to get all the keys and get the keys from the carrier.
Injects Carrier
into the current context using the current TextMap Propagator.
Injects Carrier
into the current context using the provided Propagator
.
Injects Carrier
(through CarrierSetFun
) into the current context using the provided Propagator
.
Injects Carrier
(through CarrierSetFun
) into the given Context
using the provided propagator Propagator
.
Types
-type carrier_get() :: fun((unicode:latin1_binary(), otel_propagator:carrier()) -> unicode:latin1_binary() | undefined).
-type carrier_keys() :: fun((otel_propagator:carrier()) -> [unicode:latin1_binary()]).
-type carrier_set() :: fun((unicode:latin1_binary(), unicode:latin1_binary(), otel_propagator:carrier()) -> otel_propagator:carrier()).
-type default_text_map_carrier() :: [{unicode:latin1_binary(), unicode:latin1_binary()}].
-type field_key() :: unicode:latin1_binary().
-type field_value() :: unicode:latin1_binary().
-type propagator_options() :: term().
-type t() :: module() | {module(), propagator_options()}.
Callbacks
-callback extract(otel_ctx:t(), otel_propagator:carrier(), carrier_keys(), carrier_get(), propagator_options()) -> term().
-callback fields(propagator_options()) -> [field_key()].
-callback inject(otel_ctx:t(), otel_propagator:carrier(), carrier_set(), propagator_options()) -> otel_propagator:carrier().
Functions
-spec extract(otel_propagator:carrier()) -> otel_ctx:token().
Extracts the current context from the provided Carrier
using the current TextMap Propagator.
-spec extract(otel_propagator:t(), otel_propagator:carrier()) -> otel_ctx:token().
Extracts the current context from the provided Carrier
using the given Propagator
.
-spec extract(otel_propagator:t(), otel_propagator:carrier(), fun(), fun()) -> otel_ctx:token().
Extracts the current context from the provided Carrier
using the given Propagator
and functions to get all the keys and get the keys from the carrier.
-spec extract_to(otel_ctx:t(), otel_propagator:carrier()) -> otel_ctx:t().
Equivalent to extract_to(Context, opentelemetry:get_text_map_extractor(), Carrier).
-spec extract_to(otel_ctx:t(), otel_propagator:t(), otel_propagator:carrier()) -> otel_ctx:t().
Equivalent to extract_to(Context, Propagator, Carrier, fun default_carrier_keys/1, fun default_carrier_get/2).
-spec extract_to(otel_ctx:t(), otel_propagator:t(), otel_propagator:carrier(), fun(), fun()) -> otel_ctx:t().
Extracts the current context from the provided Carrier
using the given Propagator
and functions to get all the keys and get the keys from the carrier.
-spec inject(otel_propagator:carrier()) -> otel_propagator:carrier().
Injects Carrier
into the current context using the current TextMap Propagator.
See also: inject/2.
-spec inject(otel_propagator:t(), otel_propagator:carrier()) -> otel_propagator:carrier().
Injects Carrier
into the current context using the provided Propagator
.
By default, the Carrier
is set using the a default carrier set function.
See also: inject/3.
-spec inject(otel_propagator:t(), otel_propagator:carrier(), fun()) -> otel_propagator:carrier().
Injects Carrier
(through CarrierSetFun
) into the current context using the provided Propagator
.
-spec inject_from(otel_ctx:t(), otel_propagator:carrier()) -> otel_propagator:carrier().
Equivalent to inject_from(Context, opentelemetry:get_text_map_injector(), Carrier).
-spec inject_from(otel_ctx:t(), otel_propagator:t(), otel_propagator:carrier()) -> otel_propagator:carrier().
Equivalent to inject_from(Context, Propagator, Carrier, fun default_carrier_set/3).
-spec inject_from(otel_ctx:t(), otel_propagator:t(), otel_propagator:carrier(), fun()) -> otel_propagator:carrier().
Injects Carrier
(through CarrierSetFun
) into the given Context
using the provided propagator Propagator
.