Class: OpenTelemetry::Context::Propagation::CompositePropagator
- Inherits:
-
Object
- Object
- OpenTelemetry::Context::Propagation::CompositePropagator
- Defined in:
- lib/opentelemetry/context/propagation/composite_propagator.rb
Overview
A composite propagator composes a list of injectors and extractors into single interface exposing inject and extract methods. Injection and extraction will preserve the order of the injectors and extractors passed in during initialization.
Instance Method Summary collapse
-
#extract(carrier, context = Context.current, &getter) ⇒ Context
Runs extractors in order and returns a Context updated with the results of each extraction.
-
#initialize(injectors, extractors) ⇒ CompositePropagator
constructor
Returns a Propagator that extracts using the provided extractors and injectors.
-
#inject(carrier, context = Context.current, &setter) ⇒ Object
Runs injectors in order and returns a carrier.
Constructor Details
#initialize(injectors, extractors) ⇒ CompositePropagator
Returns a Propagator that extracts using the provided extractors and injectors.
20 21 22 23 |
# File 'lib/opentelemetry/context/propagation/composite_propagator.rb', line 20 def initialize(injectors, extractors) @injectors = injectors @extractors = extractors end |
Instance Method Details
#extract(carrier, context = Context.current, &getter) ⇒ Context
Runs extractors 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.
62 63 64 65 66 67 68 69 |
# File 'lib/opentelemetry/context/propagation/composite_propagator.rb', line 62 def extract(carrier, context = Context.current, &getter) @extractors.inject(context) do |ctx, extractor| extractor.extract(carrier, ctx, &getter) rescue => e # rubocop:disable Style/RescueStandardError OpenTelemetry.logger.warn "Error in CompositePropagator#extract #{e.}" ctx end end |
#inject(carrier, context = Context.current, &setter) ⇒ Object
Runs injectors in order and returns a carrier. If an injection fails a warning will be logged and remaining injectors will be executed. Always returns a valid carrier.
39 40 41 42 43 44 45 46 |
# File 'lib/opentelemetry/context/propagation/composite_propagator.rb', line 39 def inject(carrier, context = Context.current, &setter) @injectors.inject(carrier) do |memo, injector| injector.inject(memo, context, &setter) rescue => e # rubocop:disable Style/RescueStandardError OpenTelemetry.logger.warn "Error in CompositePropagator#inject #{e.}" carrier end end |