module NewRelic::Agent::Instrumentation::ActiveRecordHelper::InstanceIdentification

Constants

DATASTORE_DEFAULT_PORTS
DEFAULT
LOCALHOST
PRODUCT_SYMBOLS
SUPPORTED_ADAPTERS
UNKNOWN

Public Instance Methods

adapter_from_config(config) click to toggle source
# File lib/new_relic/agent/instrumentation/active_record_helper.rb, line 237
def adapter_from_config(config)
  bare_name = NewRelic::Agent::Instrumentation::ActiveRecordHelper.bare_adapter_name(config[:adapter])
  PRODUCT_SYMBOLS[bare_name]
end
host(config) click to toggle source
# File lib/new_relic/agent/instrumentation/active_record_helper.rb, line 242
def host(config)
  return UNKNOWN unless config

  configured_value = config[:host]
  adapter = adapter_from_config(config)
  if configured_value.nil? ||
      postgres_unix_domain_socket_case?(configured_value, adapter)

    LOCALHOST
  elsif configured_value.empty?
    UNKNOWN
  else
    configured_value
  end
rescue => e
  NewRelic::Agent.logger.debug("Failed to retrieve ActiveRecord host: #{e}")
  UNKNOWN
end
port_path_or_id(config) click to toggle source
# File lib/new_relic/agent/instrumentation/active_record_helper.rb, line 261
def port_path_or_id(config)
  return UNKNOWN unless config

  adapter = adapter_from_config(config)
  if config[:socket]
    config[:socket].empty? ? UNKNOWN : config[:socket]
  elsif postgres_unix_domain_socket_case?(config[:host], adapter) || mysql_default_case?(config, adapter)
    DEFAULT
  elsif config[:port].nil?
    DATASTORE_DEFAULT_PORTS[adapter] || DEFAULT
  elsif config[:port].is_a?(Integer) || config[:port].to_i != 0
    config[:port].to_s
  else
    UNKNOWN
  end
rescue => e
  NewRelic::Agent.logger.debug("Failed to retrieve ActiveRecord port_path_or_id: #{e}")
  UNKNOWN
end
supported_adapter?(config) click to toggle source
# File lib/new_relic/agent/instrumentation/active_record_helper.rb, line 283
def supported_adapter?(config)
  config && SUPPORTED_ADAPTERS.include?(adapter_from_config(config))
end

Private Instance Methods

mysql_default_case?(config, adapter) click to toggle source
# File lib/new_relic/agent/instrumentation/active_record_helper.rb, line 293
def mysql_default_case?(config, adapter)
  (adapter == :mysql2 || adapter == :mysql) &&
    Hostname.local?(config[:host]) &&
    !config[:port]
end
postgres_unix_domain_socket_case?(host, adapter) click to toggle source
# File lib/new_relic/agent/instrumentation/active_record_helper.rb, line 289
def postgres_unix_domain_socket_case?(host, adapter)
  adapter == :postgres && host && host.start_with?(NewRelic::SLASH)
end