Class: Datadog::Tracing::Contrib::HTTP::Distributed::Fetcher

Inherits:
Distributed::Fetcher show all
Defined in:
lib/datadog/tracing/contrib/http/distributed/fetcher.rb

Overview

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.

Instance Method Summary collapse

Methods inherited from Distributed::Fetcher

#initialize

Constructor Details

This class inherits a constructor from Datadog::Tracing::Distributed::Fetcher

Instance Method Details

#[](name) ⇒ String?

Returns the header value or nil if not found.

Parameters:

  • name (String)

    the header name

Returns:

  • (String, nil)

    the header value or nil if not found



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/datadog/tracing/contrib/http/distributed/fetcher.rb', line 18

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