class OpenTelemetry::Context::Propagation::RackEnvGetter

The RackEnvGetter class provides a common methods for reading keys from a rack environment. It abstracts away the rack-normalization process so that keys can be looked up without having to transform them first. With this class you can get traceparent instead of HTTP_TRACEPARENT

Public Instance Methods

get(carrier, key) click to toggle source

Converts key into a rack-normalized key and reads it from the carrier. Useful for extract operations.

# File lib/opentelemetry/context/propagation/rack_env_getter.rb, line 18
def get(carrier, key)
  carrier[to_rack_key(key)] || carrier[key]
end
keys(carrier) click to toggle source

Reads all keys from a carrier and converts them from the rack-normalized form to the original. The resulting keys will be lowercase and underscores will be replaced with dashes.

# File lib/opentelemetry/context/propagation/rack_env_getter.rb, line 25
def keys(carrier)
  carrier.keys.map(&method(:from_rack_key))
end

Private Instance Methods

from_rack_key(key) click to toggle source
# File lib/opentelemetry/context/propagation/rack_env_getter.rb, line 38
def from_rack_key(key)
  start = key.start_with?('HTTP_') ? 5 : 0
  ret = key[start..-1]
  ret.tr!('_', '-')
  ret.downcase!
  ret
end
to_rack_key(key) click to toggle source
# File lib/opentelemetry/context/propagation/rack_env_getter.rb, line 31
def to_rack_key(key)
  ret = 'HTTP_' + key
  ret.tr!('-', '_')
  ret.upcase!
  ret
end