Class: Appsignal::Config
- Inherits:
-
Object
- Object
- Appsignal::Config
- Includes:
- CarefulLogger
- Defined in:
- lib/appsignal/config.rb
Constant Summary collapse
- DEFAULT_CONFIG =
{ :debug => false, :ignore_errors => [], :ignore_actions => [], :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 => true, :running_in_container => false }.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_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_ERRORS' => :ignore_errors, 'APPSIGNAL_IGNORE_ACTIONS' => :ignore_actions, '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 }.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.
-
#root_path ⇒ Object
readonly
Returns the value of attribute root_path.
Instance Method Summary collapse
- #[](key) ⇒ 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
Methods included from CarefulLogger
Constructor Details
#initialize(root_path, env, initial_config = {}, logger = Appsignal.logger) ⇒ Config
Returns a new instance of Config.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/appsignal/config.rb', line 50 def initialize(root_path, env, initial_config={}, logger=Appsignal.logger) @root_path = root_path @env = env.to_s @initial_config = initial_config @logger = logger @valid = false # Initial config @config_hash = DEFAULT_CONFIG.merge(initial_config) # Load config from environment variables load_from_environment # Load the config file if it exists if config_file && File.exists?(config_file) load_from_disk end # Validate that we have a correct config validate end |
Instance Attribute Details
#config_hash ⇒ Object (readonly)
Returns the value of attribute config_hash.
48 49 50 |
# File 'lib/appsignal/config.rb', line 48 def config_hash @config_hash end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
48 49 50 |
# File 'lib/appsignal/config.rb', line 48 def env @env end |
#initial_config ⇒ Object (readonly)
Returns the value of attribute initial_config.
48 49 50 |
# File 'lib/appsignal/config.rb', line 48 def initial_config @initial_config end |
#root_path ⇒ Object (readonly)
Returns the value of attribute root_path.
48 49 50 |
# File 'lib/appsignal/config.rb', line 48 def root_path @root_path end |
Instance Method Details
#[](key) ⇒ Object
72 73 74 |
# File 'lib/appsignal/config.rb', line 72 def [](key) config_hash[key] end |
#active? ⇒ Boolean
87 88 89 |
# File 'lib/appsignal/config.rb', line 87 def active? @valid && self[:active] end |
#log_file_path ⇒ Object
76 77 78 79 80 81 |
# File 'lib/appsignal/config.rb', line 76 def log_file_path path = config_hash[:log_path] || root_path File.join(File.realpath(path), 'appsignal.log') rescue Errno::ENOENT '/tmp/appsignal.log' end |
#valid? ⇒ Boolean
83 84 85 |
# File 'lib/appsignal/config.rb', line 83 def valid? @valid end |
#write_to_environment ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/appsignal/config.rb', line 91 def write_to_environment 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'] = Appsignal::VERSION ENV['APPSIGNAL_DEBUG_LOGGING'] = config_hash[:debug].to_s 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_RUNNING_IN_CONTAINER'] = config_hash[:running_in_container].to_s end |