Class: OpenTelemetry::Baggage::Propagation::TextMapExtractor
- Inherits:
-
Object
- Object
- OpenTelemetry::Baggage::Propagation::TextMapExtractor
- Includes:
- Context::Propagation::DefaultGetter
- Defined in:
- lib/opentelemetry/baggage/propagation/text_map_extractor.rb
Overview
Extracts baggage from carriers in the W3C Baggage format
Instance Method Summary collapse
-
#extract(carrier, context, &getter) {|Carrier, String| ... } ⇒ Context
Extract remote baggage from the supplied carrier.
-
#initialize(baggage_key: 'baggage') ⇒ TextMapExtractor
constructor
Returns a new TextMapExtractor that extracts context using the specified header key.
Methods included from Context::Propagation::DefaultGetter
Constructor Details
#initialize(baggage_key: 'baggage') ⇒ TextMapExtractor
Returns a new TextMapExtractor that extracts context using the specified header key
22 23 24 |
# File 'lib/opentelemetry/baggage/propagation/text_map_extractor.rb', line 22 def initialize(baggage_key: 'baggage') @baggage_key = baggage_key end |
Instance Method Details
#extract(carrier, context, &getter) {|Carrier, String| ... } ⇒ Context
Extract remote baggage from the supplied carrier. If extraction fails, the original context will be returned
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/opentelemetry/baggage/propagation/text_map_extractor.rb', line 38 def extract(carrier, context, &getter) getter ||= default_getter header = getter.call(carrier, @baggage_key) entries = header.gsub(/\s/, '').split(',') baggage = entries.each_with_object({}) do |entry, memo| # The ignored variable below holds properties as per the W3C spec. # OTel is not using them currently, but they might be used for # metadata in the future kv, = entry.split(';', 2) k, v = kv.split('=').map!(&CGI.method(:unescape)) memo[k] = v end context.set_value(ContextKeys.baggage_key, baggage) rescue StandardError context end |