Class: OpenTelemetry::Baggage::Propagation::TextMapPropagator
- Inherits:
-
Object
- Object
- OpenTelemetry::Baggage::Propagation::TextMapPropagator
- Defined in:
- lib/opentelemetry/baggage/propagation/text_map_propagator.rb
Overview
Propagates baggage using the W3C Baggage format
Instance Method Summary collapse
-
#extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter) ⇒ Context
Extract remote baggage from the supplied carrier.
-
#fields ⇒ Array<String>
Returns the predefined propagation fields.
-
#inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter) ⇒ Object
Inject in-process baggage into the supplied carrier.
Instance Method Details
#extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter) ⇒ Context
Extract remote baggage from the supplied carrier. If extraction fails or there is no baggage to extract, then the original context will be returned
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/opentelemetry/baggage/propagation/text_map_propagator.rb', line 54 def extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter) header = getter.get(carrier, BAGGAGE_KEY) return context if header.nil? || header.empty? entries = split_entries(header) OpenTelemetry::Baggage.build(context: context) do |builder| decode_entries(entries, builder) end rescue StandardError => e OpenTelemetry.logger.debug "Error extracting W3C baggage: #{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.
72 73 74 |
# File 'lib/opentelemetry/baggage/propagation/text_map_propagator.rb', line 72 def fields FIELDS end |
#inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter) ⇒ Object
Inject in-process baggage into the supplied carrier.
31 32 33 34 35 36 37 38 39 |
# File 'lib/opentelemetry/baggage/propagation/text_map_propagator.rb', line 31 def inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter) baggage = OpenTelemetry::Baggage.raw_entries(context: context) return if baggage.nil? || baggage.empty? encoded_baggage = encode(baggage) setter.set(carrier, BAGGAGE_KEY, encoded_baggage) if encoded_baggage && !encoded_baggage.empty? nil end |