Class: ScoutApm::Config
- Inherits:
-
Object
- Object
- ScoutApm::Config
- Defined in:
- lib/scout_apm/config.rb
Defined Under Namespace
Classes: BooleanCoercion, ConfigDefaults, ConfigEnvironment, ConfigFile, ConfigNull, IntegerCoercion, JsonCoercion, NullCoercion
Constant Summary collapse
- KNOWN_CONFIG_OPTIONS =
[ 'application_root', 'async_recording', 'collect_remote_ip', 'compress_payload', 'config_file', 'data_file', 'database_metric_limit', 'database_metric_report_limit', 'detailed_middleware', 'dev_trace', 'direct_host', 'disabled_instruments', 'enable_background_jobs', 'external_service_metric_limit', 'external_service_metric_report_limit', 'host', 'hostname', 'ignore', 'key', 'log_class', 'log_file_path', 'log_level', 'log_stderr', 'log_stdout', 'max_traces', 'monitor', 'name', 'profile', 'proxy', 'record_queue_time', 'remote_agent_host', 'remote_agent_port', 'report_format', 'revision_sha', 'scm_subdirectory', 'start_resque_server_instrument', 'ssl_cert_file', 'uri_reporting', 'instrument_http_url_length', 'timeline_traces', 'auto_instruments', 'auto_instruments_ignore', 'use_prepend', 'alias_method_instruments', 'prepend_instruments', # Error Service Related Configuration 'errors_enabled', 'errors_ignored_exceptions', 'errors_filtered_params', 'errors_host', ]
- SETTING_COERCIONS =
{ 'async_recording' => BooleanCoercion.new, 'detailed_middleware' => BooleanCoercion.new, 'dev_trace' => BooleanCoercion.new, 'enable_background_jobs' => BooleanCoercion.new, 'ignore' => JsonCoercion.new, 'max_traces' => IntegerCoercion.new, 'monitor' => BooleanCoercion.new, 'collect_remote_ip' => BooleanCoercion.new, 'compress_payload' => BooleanCoercion.new, 'database_metric_limit' => IntegerCoercion.new, 'database_metric_report_limit' => IntegerCoercion.new, 'external_service_metric_limit' => IntegerCoercion.new, 'external_service_metric_report_limit' => IntegerCoercion.new, 'instrument_http_url_length' => IntegerCoercion.new, 'record_queue_time' => BooleanCoercion.new, 'start_resque_server_instrument' => BooleanCoercion.new, 'timeline_traces' => BooleanCoercion.new, 'auto_instruments' => BooleanCoercion.new, 'auto_instruments_ignore' => JsonCoercion.new, 'use_prepend' => BooleanCoercion.new, 'alias_method_instruments' => JsonCoercion.new, 'prepend_instruments' => JsonCoercion.new, 'errors_enabled' => BooleanCoercion.new, 'errors_ignored_exceptions' => JsonCoercion.new, 'errors_filtered_params' => JsonCoercion.new, }
Class Method Summary collapse
-
.with_file(context, file_path = nil, config = {}) ⇒ Object
Load up a config instance, attempting to load a yaml file.
-
.without_file(context) ⇒ Object
Load up a config instance without attempting to load a file.
Instance Method Summary collapse
-
#all_settings ⇒ Object
Returns an array of config keys, values, and source “monitor”, value: “true”, source: “environment”.
-
#any_keys_found? ⇒ Boolean
Did we load anything for configuration?.
-
#initialize(context, overlays) ⇒ Config
constructor
A new instance of Config.
- #log_settings(logger) ⇒ Object
- #logger ⇒ Object
-
#overlay_for_key(key) ⇒ Object
For a given key, what is the first overlay says that it can handle it?.
- #value(key) ⇒ Object
Constructor Details
#initialize(context, overlays) ⇒ Config
Returns a new instance of Config.
238 239 240 241 |
# File 'lib/scout_apm/config.rb', line 238 def initialize(context, ) @context = context @overlays = Array() end |
Class Method Details
.with_file(context, file_path = nil, config = {}) ⇒ Object
Load up a config instance, attempting to load a yaml file. Allows a definite location if requested, or will attempt to load the default configuration file: APP_ROOT/config/scout_apm.yml
228 229 230 231 232 233 234 235 236 |
# File 'lib/scout_apm/config.rb', line 228 def self.with_file(context, file_path=nil, config={}) = [ ConfigEnvironment.new, ConfigFile.new(context, file_path, config), ConfigDefaults.new, ConfigNull.new, ] new(context, ) end |
.without_file(context) ⇒ Object
Load up a config instance without attempting to load a file. Useful for bootstrapping.
216 217 218 219 220 221 222 223 |
# File 'lib/scout_apm/config.rb', line 216 def self.without_file(context) = [ ConfigEnvironment.new, ConfigDefaults.new, ConfigNull.new, ] new(context, ) end |
Instance Method Details
#all_settings ⇒ Object
Returns an array of config keys, values, and source “monitor”, value: “true”, source: “environment”
273 274 275 276 277 278 |
# File 'lib/scout_apm/config.rb', line 273 def all_settings KNOWN_CONFIG_OPTIONS.inject([]) do |memo, key| o = (key) memo << {:key => key, :value => value(key).inspect, :source => o.name} end end |
#any_keys_found? ⇒ Boolean
Did we load anything for configuration?
266 267 268 |
# File 'lib/scout_apm/config.rb', line 266 def any_keys_found? @overlays.any? { || .any_keys_found? } end |
#log_settings(logger) ⇒ Object
280 281 282 283 284 285 |
# File 'lib/scout_apm/config.rb', line 280 def log_settings(logger) logger.debug( "Resolved Setting Values:\n" + all_settings.map{|hsh| "#{hsh[:source]} - #{hsh[:key]}: #{hsh[:value]}"}.join("\n") ) end |
#logger ⇒ Object
287 288 289 |
# File 'lib/scout_apm/config.rb', line 287 def logger @context.logger end |
#overlay_for_key(key) ⇒ Object
For a given key, what is the first overlay says that it can handle it?
244 245 246 |
# File 'lib/scout_apm/config.rb', line 244 def (key) @overlays.detect{ || .has_key?(key) } end |
#value(key) ⇒ Object
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/scout_apm/config.rb', line 248 def value(key) if ! KNOWN_CONFIG_OPTIONS.include?(key) logger.debug("Requested looking up a unknown configuration key: #{key} (not a problem. Evaluate and add to config.rb)") end o = (key) raw_value = if o o.value(key) else # No overlay said it could handle this key, bail out with nil. nil end coercion = SETTING_COERCIONS.fetch(key, NullCoercion.new) coercion.coerce(raw_value) end |