Otel.API.Propagator.TextMap.Composite (otel v0.2.0)

Copy Markdown View Source

Composite TextMap propagator (OTel context/api-propagators.md §Composite Propagator, L259-L305).

Groups multiple TextMap propagators into a single entity: inject/4 calls each inner propagator's inject in order on the same carrier; extract/4 threads the context through each propagator so later ones see earlier extractions.

Usage

Obtain a composite via new/1 and register it with Otel.API.Propagator.TextMap.set_propagator/1:

[Otel.API.Propagator.TextMap.TraceContext,
 Otel.API.Propagator.TextMap.Baggage]
|> Otel.API.Propagator.TextMap.Composite.new()
|> Otel.API.Propagator.TextMap.set_propagator()

Dispatch goes through the facade: Otel.API.Propagator.TextMap.inject/2,3 and extract/2,3inject_with/extract_withinject/4/extract/4 here.

Relationship to the TextMapPropagator behaviour

Composite is not itself an Otel.API.Propagator.TextMap implementation — the behaviour's callbacks are 3-arity (inject(ctx, carrier, setter)), matching single propagators like TraceContext or Baggage. Composite is a configured wrapper that requires the list of inner propagators, so its public functions are 4-arity (inject(propagators, ctx, carrier, setter)) and it is dispatched via the {Composite, propagators} tuple that new/1 returns.

The facade's inject_with/extract_with pattern-matches on this tuple shape to route to the 4-arg form, while atom-only propagators route to the 3-arg behaviour callback.

Public API

FunctionRole
new/1Application (OTel API MUST) — Create a Composite Propagator (L278-L285)
fields/1Application (OTel API MAY) — Aggregated inner-propagator Fields (L133-L152)
inject/4, extract/4SDK (dispatch target) — invoked via TextMap.inject_with/4 / extract_with/4 on the {Composite, propagators} tuple

References

  • OTel Context §Composite Propagator: opentelemetry-specification/specification/context/api-propagators.md L259-L305
  • OTel Context §Fields: opentelemetry-specification/specification/context/api-propagators.md L133-L152
  • Reference impl: opentelemetry-erlang/apps/opentelemetry_api/src/otel_propagator_text_map_composite.erl

Summary

Types

An inner propagator for composition.

Functions

SDK (dispatch target) — "Composite Extract" (api-propagators.md L286-L296).

Application (OTel API MAY) — Fields (api-propagators.md L133-L152).

SDK (dispatch target) — "Composite Inject" (api-propagators.md L297-L305).

Application (OTel API MUST) — "Create a Composite Propagator" (api-propagators.md L278-L285).

Types

propagator()

@type propagator() :: module() | {module(), term()}

An inner propagator for composition.

Either a module implementing the Otel.API.Propagator.TextMap behaviour (no options) or a {module, options} tuple for a configured propagator (currently only Composite itself uses this shape).

Functions

extract(propagators, ctx, carrier, getter)

@spec extract(
  propagators :: [propagator()],
  ctx :: Otel.API.Ctx.t(),
  carrier :: Otel.API.Propagator.TextMap.carrier(),
  getter :: Otel.API.Propagator.TextMap.getter()
) :: Otel.API.Ctx.t()

SDK (dispatch target) — "Composite Extract" (api-propagators.md L286-L296).

Calls each inner propagator's extract in order, threading the context through the reduction so later propagators see earlier extractions.

Not called directly by application code — invoked via Otel.API.Propagator.TextMap.extract_with/4 when the global propagator is a {Composite, propagators} tuple.

fields(propagators)

@spec fields(propagators :: [propagator()]) :: [String.t()]

Application (OTel API MAY) — Fields (api-propagators.md L133-L152).

Returns the deduplicated union of header keys used by all inner propagators. Deduplication prevents callers that pre-read carriers from reading the same key twice when two inner propagators share a field (rare but possible with custom compositions).

inject(propagators, ctx, carrier, setter)

SDK (dispatch target) — "Composite Inject" (api-propagators.md L297-L305).

Calls each inner propagator's inject in order on the same carrier, threading the carrier through the reduction.

Not called directly by application code — invoked via Otel.API.Propagator.TextMap.inject_with/4 when the global propagator is a {Composite, propagators} tuple.

new(propagators)

@spec new(propagators :: [propagator()]) :: {module(), [propagator()]}

Application (OTel API MUST) — "Create a Composite Propagator" (api-propagators.md L278-L285).

Returns a {Composite, propagators} tuple suitable for registration via Otel.API.Propagator.TextMap.set_propagator/1. Inner propagators are invoked in the order given.