Class: OpenTelemetry::Context::Propagation::CompositeTextMapPropagator
- Inherits:
-
Object
- Object
- OpenTelemetry::Context::Propagation::CompositeTextMapPropagator
- Defined in:
- lib/opentelemetry/context/propagation/composite_text_map_propagator.rb
Overview
A composite text map propagator either composes a list of injectors and a list of extractors, or wraps a list of propagators, into a single interface exposing inject and extract methods. Injection and extraction will preserve the order of the injectors and extractors (or propagators) passed in during initialization.
Class Method Summary collapse
-
.compose(injectors:, extractors:) ⇒ Object
Returns a Propagator that extracts using the provided extractors and injectors.
-
.compose_propagators(propagators) ⇒ Object
Returns a Propagator that extracts using the provided propagators.
Instance Method Summary collapse
-
#extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter) ⇒ Context
Runs extractors or propagators in order and returns a Context updated with the results of each extraction.
-
#fields ⇒ Array<String>
Returns the union of the propagation fields returned by the composed injectors or propagators.
-
#initialize(injectors: nil, extractors: nil, propagators: nil) ⇒ CompositeTextMapPropagator
constructor
private
A new instance of CompositeTextMapPropagator.
-
#inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter) ⇒ Object
Runs injectors or propagators in order.
Constructor Details
#initialize(injectors: nil, extractors: nil, propagators: nil) ⇒ CompositeTextMapPropagator
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of CompositeTextMapPropagator.
44 45 46 47 48 |
# File 'lib/opentelemetry/context/propagation/composite_text_map_propagator.rb', line 44 def initialize(injectors: nil, extractors: nil, propagators: nil) @injectors = injectors @extractors = extractors @propagators = propagators end |
Class Method Details
.compose(injectors:, extractors:) ⇒ Object
Returns a Propagator that extracts using the provided extractors and injectors.
24 25 26 27 28 |
# File 'lib/opentelemetry/context/propagation/composite_text_map_propagator.rb', line 24 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 |
.compose_propagators(propagators) ⇒ Object
Returns a Propagator that extracts using the provided propagators.
34 35 36 37 38 39 40 |
# File 'lib/opentelemetry/context/propagation/composite_text_map_propagator.rb', line 34 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 |
Instance Method Details
#extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter) ⇒ Context
Runs extractors or propagators in order and returns a Context updated with the results of each extraction. If an extraction fails, a warning will be logged and remaining extractors will continue to be executed. Always returns a valid context.
83 84 85 86 87 88 89 90 91 |
# File 'lib/opentelemetry/context/propagation/composite_text_map_propagator.rb', line 83 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.}" ctx end end |
#fields ⇒ Array<String>
Returns the union of the propagation fields returned by the composed injectors or propagators. If your carrier is reused, you should delete the fields returned by this method before calling inject
.
98 99 100 101 |
# File 'lib/opentelemetry/context/propagation/composite_text_map_propagator.rb', line 98 def fields injectors = @injectors || @propagators injectors.flat_map(&:fields).uniq end |
#inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter) ⇒ Object
Runs injectors or propagators in order. If an injection fails a warning will be logged and remaining injectors will be executed.
59 60 61 62 63 64 65 66 67 |
# File 'lib/opentelemetry/context/propagation/composite_text_map_propagator.rb', line 59 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.}" end nil end |