class OpenTelemetry::Context::Propagation::CompositeTextMapPropagator
initialization.
the order of the injectors and extractors (or propagators) passed in during
exposing inject and extract methods. Injection and extraction will preserve
list of extractors, or wraps a list of propagators, into a single interface
A composite text map propagator either composes a list of injectors and a
def compose(injectors:, extractors:)
-
extractors
(Array<#extract>
) -- An array of text map extractors -
injectors
(Array<#inject, #fields>
) -- An array of text map injectors
def compose(injectors:, extractors:) raise ArgumentError, 'injectors and extractors must both be non-nil arrays' unless injectors.is_a?(Array) && extractors.is_a?(Array) new(injectors: injectors, extractors: extractors) end
def compose_propagators(propagators)
-
propagators
(Array<#inject, #extract, #fields>
) -- An array of
def compose_propagators(propagators) raise ArgumentError, 'propagators must be a non-nil array' unless propagators.is_a?(Array) return NoopTextMapPropagator.new if propagators.empty? return propagators.first if propagators.size == 1 new(propagators: propagators) end
def extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter)
-
(Context)
- a new context updated with state extracted from the
Parameters:
-
getter
(optional Getter
) -- If the optional getter is provided, it -
context
(optional Context
) -- Context to be updated with the state -
carrier
(Object
) -- The carrier to extract context from.
def extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter) extractors = @extractors || @propagators extractors.inject(context) do |ctx, extractor| extractor.extract(carrier, context: ctx, getter: getter) rescue StandardError => e OpenTelemetry.logger.warn "Error in CompositePropagator#extract #{e.message}" ctx end end
def fields
-
(Array
- a list of fields that will be used by this propagator.)
def fields injectors = @injectors || @propagators injectors.flat_map(&:fields).uniq end
def initialize(injectors: nil, extractors: nil, propagators: nil)
- Api: - private
def initialize(injectors: nil, extractors: nil, propagators: nil) @injectors = injectors @extractors = extractors @propagators = propagators end
def inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter)
-
setter
(optional Setter
) -- If the optional setter is provided, it -
context
(optional Context
) -- Context to be injected into carrier. Defaults -
carrier
(Object
) -- A mutable carrier to inject context into.
def inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter) injectors = @injectors || @propagators injectors.each do |injector| injector.inject(carrier, context: context, setter: setter) rescue StandardError => e OpenTelemetry.logger.warn "Error in CompositePropagator#inject #{e.message}" end nil end