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 67 68 69 70 71 72 73 |
# 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 = header.gsub(/\s/, '').split(',') OpenTelemetry::Baggage.build(context: context) do |builder| entries.each do |entry| # Note metadata is currently unused in OpenTelemetry, but is part # the W3C spec where it's referred to as properties. We preserve # the properties (as-is) so that they can be propagated elsewhere. kv, = entry.split(';', 2) k, v = kv.split('=').map!(&CGI.method(:unescape)) builder.set_value(k, v, metadata: ) end 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
.
79 80 81 |
# File 'lib/opentelemetry/baggage/propagation/text_map_propagator.rb', line 79 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) unless encoded_baggage&.empty? nil end |