Class: Appsignal::Config
Constant Summary collapse
- DEFAULT_CONFIG =
{ :debug => false, :log => "file", :ignore_actions => [], :ignore_errors => [], :ignore_namespaces => [], :filter_parameters => [], :send_params => true, :endpoint => "https://push.appsignal.com", :instrument_net_http => true, :instrument_redis => true, :instrument_sequel => true, :skip_session_data => false, :enable_frontend_error_catching => false, :frontend_error_catching_path => "/appsignal_error_catcher", :enable_allocation_tracking => true, :enable_gc_instrumentation => false, :enable_host_metrics => true, :enable_minutely_probes => false, :hostname => ::Socket.gethostname, :ca_file_path => File.(File.join("../../../resources/cacert.pem"), __FILE__), :dns_servers => [] }.freeze
- ENV_TO_KEY_MAPPING =
{ "APPSIGNAL_ACTIVE" => :active, "APPSIGNAL_PUSH_API_KEY" => :push_api_key, "APPSIGNAL_APP_NAME" => :name, "APPSIGNAL_PUSH_API_ENDPOINT" => :endpoint, "APPSIGNAL_FRONTEND_ERROR_CATCHING_PATH" => :frontend_error_catching_path, "APPSIGNAL_DEBUG" => :debug, "APPSIGNAL_LOG" => :log, "APPSIGNAL_LOG_PATH" => :log_path, "APPSIGNAL_INSTRUMENT_NET_HTTP" => :instrument_net_http, "APPSIGNAL_INSTRUMENT_REDIS" => :instrument_redis, "APPSIGNAL_INSTRUMENT_SEQUEL" => :instrument_sequel, "APPSIGNAL_SKIP_SESSION_DATA" => :skip_session_data, "APPSIGNAL_ENABLE_FRONTEND_ERROR_CATCHING" => :enable_frontend_error_catching, "APPSIGNAL_IGNORE_ACTIONS" => :ignore_actions, "APPSIGNAL_IGNORE_ERRORS" => :ignore_errors, "APPSIGNAL_IGNORE_NAMESPACES" => :ignore_namespaces, "APPSIGNAL_FILTER_PARAMETERS" => :filter_parameters, "APPSIGNAL_SEND_PARAMS" => :send_params, "APPSIGNAL_HTTP_PROXY" => :http_proxy, "APPSIGNAL_ENABLE_ALLOCATION_TRACKING" => :enable_allocation_tracking, "APPSIGNAL_ENABLE_GC_INSTRUMENTATION" => :enable_gc_instrumentation, "APPSIGNAL_RUNNING_IN_CONTAINER" => :running_in_container, "APPSIGNAL_WORKING_DIR_PATH" => :working_dir_path, "APPSIGNAL_ENABLE_HOST_METRICS" => :enable_host_metrics, "APPSIGNAL_ENABLE_MINUTELY_PROBES" => :enable_minutely_probes, "APPSIGNAL_HOSTNAME" => :hostname, "APPSIGNAL_CA_FILE_PATH" => :ca_file_path, "APPSIGNAL_DNS_SERVERS" => :dns_servers }.freeze
Instance Attribute Summary collapse
-
#config_hash ⇒ Object
readonly
Returns the value of attribute config_hash.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#initial_config ⇒ Object
readonly
Returns the value of attribute initial_config.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#root_path ⇒ Object
readonly
Returns the value of attribute root_path.
Class Method Summary collapse
-
.system_tmp_dir ⇒ String
private
System's tmp directory.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #active? ⇒ Boolean
-
#initialize(root_path, env, initial_config = {}, logger = Appsignal.logger) ⇒ Config
constructor
A new instance of Config.
- #log_file_path ⇒ Object
- #valid? ⇒ Boolean
-
#write_to_environment ⇒ Object
rubocop:disable Metrics/AbcSize.
Constructor Details
#initialize(root_path, env, initial_config = {}, logger = Appsignal.logger) ⇒ Config
Returns a new instance of Config.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/appsignal/config.rb', line 67 def initialize(root_path, env, initial_config = {}, logger = Appsignal.logger) @root_path = root_path @env = ENV.fetch("APPSIGNAL_APP_ENV".freeze, env.to_s) @initial_config = initial_config @logger = logger @valid = false @config_hash = Hash[DEFAULT_CONFIG] # Set config based on the system detect_from_system # Initial config merge(@config_hash, initial_config) # Load the config file if it exists load_from_disk # Load config from environment variables load_from_environment # Validate that we have a correct config validate end |
Instance Attribute Details
#config_hash ⇒ Object (readonly)
Returns the value of attribute config_hash.
64 65 66 |
# File 'lib/appsignal/config.rb', line 64 def config_hash @config_hash end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
64 65 66 |
# File 'lib/appsignal/config.rb', line 64 def env @env end |
#initial_config ⇒ Object (readonly)
Returns the value of attribute initial_config.
64 65 66 |
# File 'lib/appsignal/config.rb', line 64 def initial_config @initial_config end |
#logger ⇒ Object
Returns the value of attribute logger.
65 66 67 |
# File 'lib/appsignal/config.rb', line 65 def logger @logger end |
#root_path ⇒ Object (readonly)
Returns the value of attribute root_path.
64 65 66 |
# File 'lib/appsignal/config.rb', line 64 def root_path @root_path end |
Class Method Details
.system_tmp_dir ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns System's tmp directory.
89 90 91 92 93 94 95 |
# File 'lib/appsignal/config.rb', line 89 def self.system_tmp_dir if Gem.win_platform? Dir.tmpdir else File.realpath("/tmp") end end |
Instance Method Details
#[](key) ⇒ Object
97 98 99 |
# File 'lib/appsignal/config.rb', line 97 def [](key) config_hash[key] end |
#[]=(key, value) ⇒ Object
101 102 103 |
# File 'lib/appsignal/config.rb', line 101 def []=(key, value) config_hash[key] = value end |
#active? ⇒ Boolean
128 129 130 |
# File 'lib/appsignal/config.rb', line 128 def active? @valid && config_hash[:active] end |
#log_file_path ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/appsignal/config.rb', line 105 def log_file_path path = config_hash[:log_path] || root_path && File.join(root_path, "log") if path && File.writable?(path) return File.join(File.realpath(path), "appsignal.log") end system_tmp_dir = self.class.system_tmp_dir if File.writable? system_tmp_dir $stdout.puts "appsignal: Unable to log to '#{path}'. Logging to "\ "'#{system_tmp_dir}' instead. Please check the "\ "permissions for the application's (log) directory." File.join(system_tmp_dir, "appsignal.log") else $stdout.puts "appsignal: Unable to log to '#{path}' or the "\ "'#{system_tmp_dir}' fallback. Please check the permissions "\ "for the application's (log) directory." end end |
#valid? ⇒ Boolean
124 125 126 |
# File 'lib/appsignal/config.rb', line 124 def valid? @valid end |
#write_to_environment ⇒ Object
rubocop:disable Metrics/AbcSize
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/appsignal/config.rb', line 132 def write_to_environment # rubocop:disable Metrics/AbcSize ENV["_APPSIGNAL_ACTIVE"] = active?.to_s ENV["_APPSIGNAL_APP_PATH"] = root_path.to_s ENV["_APPSIGNAL_AGENT_PATH"] = File.("../../../ext", __FILE__).to_s ENV["_APPSIGNAL_ENVIRONMENT"] = env ENV["_APPSIGNAL_AGENT_VERSION"] = Appsignal::Extension.agent_version ENV["_APPSIGNAL_LANGUAGE_INTEGRATION_VERSION"] = "ruby-#{Appsignal::VERSION}" ENV["_APPSIGNAL_DEBUG_LOGGING"] = config_hash[:debug].to_s ENV["_APPSIGNAL_LOG"] = config_hash[:log] ENV["_APPSIGNAL_LOG_FILE_PATH"] = log_file_path.to_s if log_file_path ENV["_APPSIGNAL_PUSH_API_ENDPOINT"] = config_hash[:endpoint] ENV["_APPSIGNAL_PUSH_API_KEY"] = config_hash[:push_api_key] ENV["_APPSIGNAL_APP_NAME"] = config_hash[:name] ENV["_APPSIGNAL_HTTP_PROXY"] = config_hash[:http_proxy] ENV["_APPSIGNAL_IGNORE_ACTIONS"] = config_hash[:ignore_actions].join(",") ENV["_APPSIGNAL_IGNORE_ERRORS"] = config_hash[:ignore_errors].join(",") ENV["_APPSIGNAL_IGNORE_NAMESPACES"] = config_hash[:ignore_namespaces].join(",") ENV["_APPSIGNAL_FILTER_PARAMETERS"] = config_hash[:filter_parameters].join(",") ENV["_APPSIGNAL_SEND_PARAMS"] = config_hash[:send_params].to_s ENV["_APPSIGNAL_RUNNING_IN_CONTAINER"] = config_hash[:running_in_container].to_s ENV["_APPSIGNAL_WORKING_DIR_PATH"] = config_hash[:working_dir_path] if config_hash[:working_dir_path] ENV["_APPSIGNAL_ENABLE_HOST_METRICS"] = config_hash[:enable_host_metrics].to_s ENV["_APPSIGNAL_ENABLE_MINUTELY_PROBES"] = config_hash[:enable_minutely_probes].to_s ENV["_APPSIGNAL_HOSTNAME"] = config_hash[:hostname].to_s ENV["_APPSIGNAL_PROCESS_NAME"] = $PROGRAM_NAME ENV["_APPSIGNAL_CA_FILE_PATH"] = config_hash[:ca_file_path].to_s ENV["_APPSIGNAL_DNS_SERVERS"] = config_hash[:dns_servers].join(",") end |