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', 'compress_payload', 'config_file', 'data_file', 'database_metric_limit', 'database_metric_report_limit', 'detailed_middleware', 'dev_trace', 'direct_host', 'disabled_instruments', 'enable_background_jobs', 'host', 'hostname', 'ignore', 'key', 'log_class', 'log_file_path', 'log_level', 'log_stderr', 'log_stdout', 'max_traces', 'monitor', 'name', 'profile', 'proxy', 'remote_agent_host', 'remote_agent_port', 'report_format', 'scm_subdirectory', 'uri_reporting', 'instrument_http_url_length', ]
- 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, 'database_metric_limit' => IntegerCoercion.new, 'database_metric_report_limit' => IntegerCoercion.new, 'instrument_http_url_length' => IntegerCoercion.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.
192 193 194 195 |
# File 'lib/scout_apm/config.rb', line 192 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
182 183 184 185 186 187 188 189 190 |
# File 'lib/scout_apm/config.rb', line 182 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.
170 171 172 173 174 175 176 177 |
# File 'lib/scout_apm/config.rb', line 170 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”
227 228 229 230 231 232 |
# File 'lib/scout_apm/config.rb', line 227 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?
220 221 222 |
# File 'lib/scout_apm/config.rb', line 220 def any_keys_found? @overlays.any? { || .any_keys_found? } end |
#log_settings(logger) ⇒ Object
234 235 236 237 238 239 |
# File 'lib/scout_apm/config.rb', line 234 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
241 242 243 |
# File 'lib/scout_apm/config.rb', line 241 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?
198 199 200 |
# File 'lib/scout_apm/config.rb', line 198 def (key) @overlays.detect{ || .has_key?(key) } end |
#value(key) ⇒ Object
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/scout_apm/config.rb', line 202 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 |