Module: Contrast::Logger::Application

Includes:
Components::Interface
Defined in:
lib/contrast/logger/application.rb

Overview

Our decorator for the Ougai logger allowing for the logging of the application environment, used to provide context during troubleshooting.

Constant Summary collapse

ENV_KEYS =
%w[HOME PWD RACK_ENV RAILS_ENV RUBY_VERSION GEM_HOME GEM_PATH].cs__freeze
FRAMEWORKS =
%w[rails sinatra grape].cs__freeze
WEB_SERVERS =
%w[agoo falcon hoof iodine mongrel mongrel2 passenger puma rack skinny thin trinidad unicorn webrick yarn].cs__freeze
LIBRARIES =
%w[excon json mongo moped mysql nokogiri oga ox pg psych sqlite3 typhoeus yaml].cs__freeze

Instance Method Summary collapse

Methods included from Components::Interface

included

Instance Method Details

#application_configurationObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/contrast/logger/application.rb', line 33

def application_configuration
  return unless info?

  loggable = CONFIG.loggable
  info('Current configuration', configuration: loggable)
  env_keys = ENV.keys.select { |env_key| env_key&.to_s&.start_with?(Contrast::Components::Config::CONTRAST_ENV_MARKER) }
  env_items = env_keys.map { |env_key| Contrast::Utils::EnvConfigurationItem.new(env_key, nil) }
  env_translations = env_items.each_with_object({}) do |conversion, hash|
    hash[conversion.key] = conversion.dot_path_array.join('.')
  end
  info('Set by environment', overrides: env_translations)
rescue StandardError => e
  puts e
  sleep(5)
end

#application_environmentObject

Utility method to log some current ruby and rails information from environment



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/contrast/logger/application.rb', line 16

def application_environment
  return unless info?

  info('Process environment information',
       p_id: Process.pid,
       pp_id: Process.ppid,
       agent_version: Contrast::Agent::VERSION)
  ENV.each do |env_key, env_value|
    env_key = env_key.to_s
    next unless ENV_KEYS.include?(env_key) ||
        (env_key.start_with?(Contrast::Components::Config::CONTRAST_ENV_MARKER) &&
            !env_key.start_with?(Contrast::Components::Config::CONTRAST_ENV_MARKER + 'API'))

    info('Environment settings', key: env_key, value: env_value)
  end
end

#application_librariesObject



49
50
51
52
53
54
55
# File 'lib/contrast/logger/application.rb', line 49

def application_libraries
  if debug?
    log_all_libraries
  elsif info?
    log_specific_libraries
  end
end

#log_specific_librariesObject



60
61
62
63
64
# File 'lib/contrast/logger/application.rb', line 60

def log_specific_libraries
  FRAMEWORKS.each(&cs__method(:log_gem_data))
  WEB_SERVERS.each(&cs__method(:log_gem_data))
  LIBRARIES.each(&cs__method(:log_gem_data))
end