otel_propagator_text_map behaviour (OpenTelemetry API v1.4.0)

View Source

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/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

carrier_get/0

-type carrier_get() ::
          fun((unicode:latin1_binary(), otel_propagator:carrier()) ->
                  unicode:latin1_binary() | undefined).

carrier_keys/0

-type carrier_keys() :: fun((otel_propagator:carrier()) -> [unicode:latin1_binary()]).

carrier_set/0

default_text_map_carrier/0

-type default_text_map_carrier() :: [{unicode:latin1_binary(), unicode:latin1_binary()}].

field_key/0

-type field_key() :: unicode:latin1_binary().

field_value/0

-type field_value() :: unicode:latin1_binary().

propagator_options/0

-type propagator_options() :: term().

t/0

-type t() :: module() | {module(), propagator_options()}.

Callbacks

extract/5

fields/1

-callback fields(propagator_options()) -> [field_key()].

inject/4

Functions

extract(Carrier)

-spec extract(otel_propagator:carrier()) -> otel_ctx:token().

Extracts the current context from the provided Carrier using the current TextMap Propagator.

extract(Propagator, Carrier)

Extracts the current context from the provided Carrier using the given Propagator.

extract(Propagator, Carrier, CarrierKeysFun, CarrierGetFun)

-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.

extract_to(Context, Carrier)

-spec extract_to(otel_ctx:t(), otel_propagator:carrier()) -> otel_ctx:t().

Equivalent to extract_to(Context, opentelemetry:get_text_map_extractor(), Carrier).

extract_to(Context, Propagator, Carrier)

Equivalent to extract_to(Context, Propagator, Carrier, fun default_carrier_keys/1, fun default_carrier_get/2).

extract_to(Context, Propagator, Carrier, CarrierKeysFun, CarrierGetFun)

-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.

inject(Carrier)

Injects Carrier into the current context using the current TextMap Propagator.

See also: inject/2.

inject(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.

inject(Propagator, Carrier, CarrierSetFun)

Injects Carrier (through CarrierSetFun) into the current context using the provided Propagator.

inject_from(Context, Carrier)

Equivalent to inject_from(Context, opentelemetry:get_text_map_injector(), Carrier).

inject_from(Context, Propagator, Carrier)

Equivalent to inject_from(Context, Propagator, Carrier, fun default_carrier_set/3).

inject_from(Context, Propagator, Carrier, CarrierSetFun)

Injects Carrier (through CarrierSetFun) into the given Context using the provided propagator Propagator.