Class: OpenTelemetry::Context::Propagation::TextMapPropagator
- Inherits:
-
Object
- Object
- OpenTelemetry::Context::Propagation::TextMapPropagator
- Defined in:
- lib/opentelemetry/context/propagation/text_map_propagator.rb
Overview
A text map propagator that composes an extractor and injector into a single interface exposing inject and extract methods.
Instance Method Summary collapse
-
#extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter) ⇒ Context
Extracts and returns context from a carrier.
-
#fields ⇒ Array<String>
Returns the predefined propagation fields.
-
#initialize(injector, extractor) ⇒ TextMapPropagator
constructor
Returns a Propagator that delegates inject and extract to the provided injector and extractor.
-
#inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter) ⇒ Object
Injects the provided context into a carrier using the underlying injector.
Constructor Details
#initialize(injector, extractor) ⇒ TextMapPropagator
Returns a Propagator that delegates inject and extract to the provided injector and extractor
18 19 20 21 22 23 |
# File 'lib/opentelemetry/context/propagation/text_map_propagator.rb', line 18 def initialize(injector, extractor) raise ArgumentError, 'injector and extractor must both be non-nil' if injector.nil? || extractor.nil? @injector = injector @extractor = extractor end |
Instance Method Details
#extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter) ⇒ Context
Extracts and returns context from a carrier. Returns the provided context and logs a warning if an error if extraction fails.
54 55 56 57 58 59 |
# File 'lib/opentelemetry/context/propagation/text_map_propagator.rb', line 54 def extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter) @extractor.extract(carrier, context, getter) rescue StandardError => e OpenTelemetry.logger.warn "Error in Propagator#extract #{e.}" context end |
#fields ⇒ Array<String>
Returns the predefined propagation fields. If your carrier is reused, you should delete the fields returned by this method before calling inject
.
65 66 67 |
# File 'lib/opentelemetry/context/propagation/text_map_propagator.rb', line 65 def fields @injector.fields end |
#inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter) ⇒ Object
Injects the provided context into a carrier using the underlying injector. Logs a warning if injection fails.
34 35 36 37 38 39 40 |
# File 'lib/opentelemetry/context/propagation/text_map_propagator.rb', line 34 def inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter) @injector.inject(carrier, context, setter) nil rescue StandardError => e OpenTelemetry.logger.warn "Error in Propagator#inject #{e.}" nil end |