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', 'ignore_endpoints', 'ignore_jobs', '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', 'sample_rate', 'sample_endpoints', 'sample_jobs', 'endpoint_sample_rate', 'job_sample_rate', '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, 'ignore_endpoints' => JsonCoercion.new, 'ignore_jobs' => 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, 'sample_rate' => IntegerCoercion.new, 'sample_endpoints' => JsonCoercion.new, 'sample_jobs' => JsonCoercion.new, 'endpoint_sample_rate' => IntegerCoercion.new, 'job_sample_rate' => IntegerCoercion.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.
259 260 261 262 |
# File 'lib/scout_apm/config.rb', line 259 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
249 250 251 252 253 254 255 256 257 |
# File 'lib/scout_apm/config.rb', line 249 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.
237 238 239 240 241 242 243 244 |
# File 'lib/scout_apm/config.rb', line 237 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”
294 295 296 297 298 299 |
# File 'lib/scout_apm/config.rb', line 294 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?
287 288 289 |
# File 'lib/scout_apm/config.rb', line 287 def any_keys_found? @overlays.any? { || .any_keys_found? } end |
#log_settings(logger) ⇒ Object
301 302 303 304 305 306 |
# File 'lib/scout_apm/config.rb', line 301 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
308 309 310 |
# File 'lib/scout_apm/config.rb', line 308 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?
265 266 267 |
# File 'lib/scout_apm/config.rb', line 265 def (key) @overlays.detect{ || .has_key?(key) } end |
#value(key) ⇒ Object
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/scout_apm/config.rb', line 269 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 |