Sha256: 1247a401fb6d989761fbe00e16f92ff877a8f13df59575b8795ddc7fdf0f6518

Contents?: true

Size: 1.15 KB

Versions: 17

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: false

require_relative '../../../distributed/fetcher'

module Datadog
  module Tracing
    module Contrib
      module HTTP
        module Distributed
          # Retrieves HTTP headers from carrier.
          # Headers will also match if Rack-formatted:
          # 'my-header' will match 'my-header' and 'HTTP_MY_HEADER'.
          #
          # In case both variants are present, the verbatim match will be used.
          class Fetcher < Tracing::Distributed::Fetcher
            # @param [String] name the header name
            # @return [String, nil] the header value or nil if not found
            def [](name)
              # Try to fetch with the plain key
              value = super(name)
              return value if value && !value.empty?

              # If not found, try the Rack-formatted key
              rack_header = "HTTP-#{name}"
              rack_header.upcase!
              rack_header.tr!('-'.freeze, '_'.freeze)

              hdr = super(rack_header)

              # Only return the value if it is not an empty string
              hdr if hdr != ''
            end
          end
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
datadog-2.7.0 lib/datadog/tracing/contrib/http/distributed/fetcher.rb
datadog-2.6.0 lib/datadog/tracing/contrib/http/distributed/fetcher.rb
datadog-2.5.0 lib/datadog/tracing/contrib/http/distributed/fetcher.rb
datadog-2.4.0 lib/datadog/tracing/contrib/http/distributed/fetcher.rb
datadog-2.3.0 lib/datadog/tracing/contrib/http/distributed/fetcher.rb
datadog-2.2.0 lib/datadog/tracing/contrib/http/distributed/fetcher.rb
ddtrace-1.23.3 lib/datadog/tracing/contrib/http/distributed/fetcher.rb
ddtrace-1.23.2 lib/datadog/tracing/contrib/http/distributed/fetcher.rb
datadog-2.1.0 lib/datadog/tracing/contrib/http/distributed/fetcher.rb
datadog-2.0.0 lib/datadog/tracing/contrib/http/distributed/fetcher.rb
ddtrace-1.23.1 lib/datadog/tracing/contrib/http/distributed/fetcher.rb
datadog-2.0.0.beta2 lib/datadog/tracing/contrib/http/distributed/fetcher.rb
ddtrace-1.22.0 lib/datadog/tracing/contrib/http/distributed/fetcher.rb
datadog-2.0.0.beta1 lib/datadog/tracing/contrib/http/distributed/fetcher.rb
ddtrace-1.21.1 lib/datadog/tracing/contrib/http/distributed/fetcher.rb
ddtrace-1.21.0 lib/datadog/tracing/contrib/http/distributed/fetcher.rb
ddtrace-1.20.0 lib/datadog/tracing/contrib/http/distributed/fetcher.rb