module Datadog::Tracing::ClientIp

def configuration

def configuration
  Datadog.configuration.tracing.client_ip
end

def extract_client_ip(headers, remote_ip)

def extract_client_ip(headers, remote_ip)
  if headers && configuration.header_name
    return Datadog::Core::Utils::Network.stripped_ip_from_request_headers(
      headers,
      ip_headers_to_check: Array(configuration.header_name)
    )
  end
  ip_from_headers = Datadog::Core::Utils::Network.stripped_ip_from_request_headers(headers) if headers
  ip_from_headers || Datadog::Core::Utils::Network.stripped_ip(remote_ip)
end

def set_client_ip_tag(span, headers: nil, remote_ip: nil)

Parameters:
  • remote_ip (String, nil) -- The remote IP the request associated with the span is sent to.
  • headers (HeaderCollection, #get, nil) -- A collection with the request headers.
  • span (Span) -- The span that's associated with the request.
def set_client_ip_tag(span, headers: nil, remote_ip: nil)
  return unless configuration.enabled
  set_client_ip_tag!(span, headers: headers, remote_ip: remote_ip)
end

def set_client_ip_tag!(span, headers: nil, remote_ip: nil)

Parameters:
  • remote_ip (String, nil) -- The remote IP the request associated with the span is sent to.
  • headers (HeaderCollection, #get, nil) -- A collection with the request headers.
  • span (Span) -- The span that's associated with the request.
def set_client_ip_tag!(span, headers: nil, remote_ip: nil)
  ip = extract_client_ip(headers, remote_ip)
  span.set_tag(Tracing::Metadata::Ext::HTTP::TAG_CLIENT_IP, ip) if ip
end