Module: Contrast::Logger::Application

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

Instance Method Details

#application_configurationObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/contrast/logger/application.rb', line 27

def application_configuration
  return unless info?

  loggable = ::Contrast::CONFIG.loggable
  info('Current configuration', configuration: loggable)
  env_keys = ENV.keys.select do |env_key|
    env_key&.to_s&.start_with?(Contrast::Configuration::CONTRAST_ENV_MARKER)
  end
  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)
end

#application_environmentObject

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



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/contrast/logger/application.rb', line 11

def application_environment
  return unless info?

  info('Process environment information', p_id: Process.pid, pp_id: Process.ppid,
                                          agent_version: Contrast::Agent::VERSION,
                                          ruby_version: RUBY_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::Configuration::CONTRAST_ENV_MARKER) &&
            !env_key.start_with?("#{ Contrast::Configuration::CONTRAST_ENV_MARKER }API"))

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

#application_librariesObject



42
43
44
45
46
47
48
# File 'lib/contrast/logger/application.rb', line 42

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

#log_specific_librariesObject



56
57
58
59
60
# File 'lib/contrast/logger/application.rb', line 56

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