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, the original context will be returned
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/opentelemetry/baggage/propagation/text_map_propagator.rb', line 53 def extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter) header = getter.get(carrier, BAGGAGE_KEY) 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
.
77 78 79 |
# File 'lib/opentelemetry/baggage/propagation/text_map_propagator.rb', line 77 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 |