View Source otel_propagator_text_map behaviour (opentelemetry_api v1.3.0)
A 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
and extract
work on a generic list of 2-tuple's with binary string keys and values. A user defined function for setting a key/value in the carrier and for getting the value of a key from a carrier can be passed as an argument. 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">>}.
Link to this section Summary
Link to this section 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()}.
Link to this section 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().
Link to this section Functions
-spec default_carrier_get(field_key(), default_text_map_carrier()) -> field_value() | undefined.
-spec default_carrier_keys(default_text_map_carrier()) -> [field_key()].
-spec default_carrier_set(field_key(), field_value(), default_text_map_carrier()) -> default_text_map_carrier().
-spec extract(otel_propagator:carrier()) -> otel_ctx:token().
-spec extract(otel_propagator:t(), otel_propagator:carrier()) -> otel_ctx:token().
-spec extract(otel_propagator:t(), otel_propagator:carrier(), fun(), fun()) -> otel_ctx:token().
-spec extract_to(otel_ctx:t(), otel_propagator:carrier()) -> otel_ctx:t().
-spec extract_to(otel_ctx:t(), otel_propagator:t(), otel_propagator:carrier()) -> otel_ctx:t().
Link to this function
extract_to(Context, Module, Carrier, CarrierKeysFun, CarrierGetFun)
View Source-spec extract_to(otel_ctx:t(), otel_propagator:t(), otel_propagator:carrier(), fun(), fun()) -> otel_ctx:t().
-spec fields(otel_propagator:t()) -> [field_key()].
-spec inject(otel_propagator:carrier()) -> otel_propagator:carrier().
-spec inject(otel_propagator:t(), otel_propagator:carrier()) -> otel_propagator:carrier().
-spec inject(otel_propagator:t(), otel_propagator:carrier(), fun()) -> otel_propagator:carrier().
-spec inject_from(otel_ctx:t(), otel_propagator:carrier()) -> otel_propagator:carrier().
-spec inject_from(otel_ctx:t(), otel_propagator:t(), otel_propagator:carrier()) -> otel_propagator:carrier().
-spec inject_from(otel_ctx:t(), otel_propagator:t(), otel_propagator:carrier(), fun()) -> otel_propagator:carrier().