Module: Datadog::Tracing::ClientIp

Defined in:
lib/datadog/tracing/client_ip.rb

Overview

Common functions for supporting the ‘http.client_ip` span attribute.

Class Method Summary collapse

Class Method Details

.extract_client_ip(headers, remote_ip) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/datadog/tracing/client_ip.rb', line 40

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

.set_client_ip_tag(span, headers: nil, remote_ip: nil) ⇒ Object

Sets the ‘http.client_ip` tag on the given span.

This function respects the user’s settings: if they disable the client IP tagging,

or provide a different IP header name.

Parameters:

  • span (Span)

    The span that’s associated with the request.

  • headers (HeaderCollection, #get, nil) (defaults to: nil)

    A collection with the request headers.

  • remote_ip (String, nil) (defaults to: nil)

    The remote IP the request associated with the span is sent to.



21
22
23
24
25
# File 'lib/datadog/tracing/client_ip.rb', line 21

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

.set_client_ip_tag!(span, headers: nil, remote_ip: nil) ⇒ Object

Forcefully sets the ‘http.client_ip` tag on the given span.

This function ignores the user’s ‘enabled` setting.

Parameters:

  • span (Span)

    The span that’s associated with the request.

  • headers (HeaderCollection, #get, nil) (defaults to: nil)

    A collection with the request headers.

  • remote_ip (String, nil) (defaults to: nil)

    The remote IP the request associated with the span is sent to.



34
35
36
37
38
# File 'lib/datadog/tracing/client_ip.rb', line 34

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