lib/opentelemetry/baggage/propagation/text_map_extractor.rb in opentelemetry-api-0.13.0 vs lib/opentelemetry/baggage/propagation/text_map_extractor.rb in opentelemetry-api-0.14.0

- old
+ new

@@ -9,36 +9,33 @@ module OpenTelemetry module Baggage module Propagation # Extracts baggage from carriers in the W3C Baggage format class TextMapExtractor - include Context::Propagation::DefaultGetter - # Returns a new TextMapExtractor that extracts context using the specified - # header key + # getter # - # @param [String] baggage_key The baggage header - # key used in the carrier + # @param [optional Getter] default_getter The default getter used to read + # headers from a carrier during extract. Defaults to a + # {OpenTelemetry::Context::Propagation::TextMapGetter} instance. # @return [TextMapExtractor] - def initialize(baggage_key: 'baggage') - @baggage_key = baggage_key + def initialize(default_getter = Context::Propagation.text_map_getter) + @default_getter = default_getter end # Extract remote baggage from the supplied carrier. # If extraction fails, the original context will be returned # # @param [Carrier] carrier The carrier to get the header from # @param [Context] context The context to be updated with extracted baggage - # @param [optional Callable] getter An optional callable that takes a carrier and a key and - # returns the value associated with the key. If omitted the default getter will be used - # which expects the carrier to respond to [] and []=. - # @yield [Carrier, String] if an optional getter is provided, extract will yield the carrier - # and the header key to the getter. + # @param [optional Getter] getter If the optional getter is provided, it + # will be used to read the header from the carrier, otherwise the default + # getter will be used. # @return [Context] context updated with extracted baggage, or the original context # if extraction fails - def extract(carrier, context, &getter) - getter ||= default_getter - header = getter.call(carrier, @baggage_key) + def extract(carrier, context, getter = nil) + getter ||= @default_getter + header = getter.get(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.