module Datadog::Diagnostics::EnvironmentLogger

A holistic collection of the environment in which ddtrace is running. This logger should allow for easy reporting by users to Datadog support.

Constants

REPL_PROGRAM_NAMES

Public Class Methods

log!(transport_responses) click to toggle source

Outputs environment information to {Datadog.logger}. Executes only for the lifetime of the program.

# File lib/ddtrace/diagnostics/environment_logger.rb, line 15
def log!(transport_responses)
  return if (defined?(@executed) && @executed) || !log?

  @executed = true

  data = EnvironmentCollector.new.collect!(transport_responses)
  data.reject! { |_, v| v.nil? } # Remove empty values from hash output

  log_environment!(data.to_json)
  log_error!('Agent Error'.freeze, data[:agent_error]) if data[:agent_error]
rescue => e
  Datadog.logger.warn("Failed to collect environment information: #{e} Location: #{Array(e.backtrace).first}")
end

Private Class Methods

log?() click to toggle source

Are we logging the environment data?

# File lib/ddtrace/diagnostics/environment_logger.rb, line 40
def log?
  startup_logs_enabled = Datadog.configuration.diagnostics.startup_logs.enabled
  if startup_logs_enabled.nil?
    !repl? # Suppress logs if we running in a REPL
  else
    startup_logs_enabled
  end
end
log_environment!(line) click to toggle source
# File lib/ddtrace/diagnostics/environment_logger.rb, line 31
def log_environment!(line)
  Datadog.logger.info("DATADOG TRACER CONFIGURATION - #{line}")
end
log_error!(type, error) click to toggle source
# File lib/ddtrace/diagnostics/environment_logger.rb, line 35
def log_error!(type, error)
  Datadog.logger.warn("DATADOG TRACER DIAGNOSTIC - #{type}: #{error}")
end
repl?() click to toggle source
# File lib/ddtrace/diagnostics/environment_logger.rb, line 51
def repl?
  REPL_PROGRAM_NAMES.include?($PROGRAM_NAME)
end