Class: NewRelic::Agent::Configuration::DefaultSource
- Inherits:
-
Object
- Object
- NewRelic::Agent::Configuration::DefaultSource
- Extended by:
- Forwardable
- Defined in:
- lib/new_relic/agent/configuration/default_source.rb
Constant Summary collapse
- DEFAULT_LOG_DIR =
'log/'.freeze
Instance Attribute Summary collapse
- #defaults ⇒ Object readonly
Class Method Summary collapse
- .agent_enabled ⇒ Object
- .allowlist_for(key) ⇒ Object
- .app_name ⇒ Object
- .audit_log_path ⇒ Object
- .config_path ⇒ Object
- .config_search_paths ⇒ Object
- .convert_to_constant_list(string_array) ⇒ Object
- .convert_to_regexp_list(string_array) ⇒ Object
- .default_for(key) ⇒ Object
- .default_settings(key) ⇒ Object
- .dispatcher ⇒ Object
- .framework ⇒ Object
- .host ⇒ Object
- .profiling_available ⇒ Object
- .thread_profiler_enabled ⇒ Object
- .transaction_tracer_transaction_threshold ⇒ Object
- .transform_for(key) ⇒ Object
- .value_from_defaults(key, subkey) ⇒ Object
Instance Method Summary collapse
- #default_values ⇒ Object
-
#initialize ⇒ DefaultSource
constructor
A new instance of DefaultSource.
Constructor Details
#initialize ⇒ DefaultSource
Returns a new instance of DefaultSource.
45 46 47 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 45 def initialize @defaults = default_values end |
Instance Attribute Details
#defaults ⇒ Object (readonly)
40 41 42 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 40 def defaults @defaults end |
Class Method Details
.agent_enabled ⇒ Object
145 146 147 148 149 150 151 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 145 def self.agent_enabled proc { NewRelic::Agent.config[:enabled] && (NewRelic::Agent.config[:test_mode] || NewRelic::Agent.config[:monitor_mode]) && NewRelic::Agent::Autostart.agent_should_start? } end |
.allowlist_for(key) ⇒ Object
65 66 67 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 65 def self.allowlist_for(key) value_from_defaults(key, :allowlist) end |
.app_name ⇒ Object
165 166 167 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 165 def self.app_name proc { NewRelic::Control.instance.env } end |
.audit_log_path ⇒ Object
155 156 157 158 159 160 161 162 163 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 155 def self.audit_log_path proc { log_file_path = NewRelic::Agent.config[:log_file_path] wants_stdout = (log_file_path.casecmp(NewRelic::STANDARD_OUT) == 0) audit_log_dir = wants_stdout ? DEFAULT_LOG_DIR : log_file_path File.join(audit_log_dir, 'newrelic_audit.log') } end |
.config_path ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 112 def self.config_path proc { found_path = NewRelic::Agent.config[:config_search_paths].detect do |file| File.(file) if File.exist?(file) end found_path || NewRelic::EMPTY_STR } end |
.config_search_paths ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 77 def self.config_search_paths proc { yaml = 'newrelic.yml' config_yaml = File.join('config', yaml) erb = 'newrelic.yml.erb' config_erb = File.join('config', erb) paths = [config_yaml, yaml, config_erb, erb] if NewRelic::Control.instance.root paths << File.join(NewRelic::Control.instance.root, config_yaml) paths << File.join(NewRelic::Control.instance.root, yaml) paths << File.join(NewRelic::Control.instance.root, config_erb) paths << File.join(NewRelic::Control.instance.root, erb) end if ENV['HOME'] paths << File.join(ENV['HOME'], '.newrelic', yaml) paths << File.join(ENV['HOME'], yaml) paths << File.join(ENV['HOME'], '.newrelic', erb) paths << File.join(ENV['HOME'], erb) end # If we're packaged for warbler, we can tell from GEM_HOME # the following line needs else branch coverage if ENV['GEM_HOME'] && ENV['GEM_HOME'].end_with?('.jar!') # rubocop:disable Style/SafeNavigation app_name = File.basename(ENV['GEM_HOME'], '.jar!') paths << File.join(ENV['GEM_HOME'], app_name, config_yaml) paths << File.join(ENV['GEM_HOME'], app_name, config_erb) end paths } end |
.convert_to_constant_list(string_array) ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 207 def self.convert_to_constant_list(string_array) return string_array if string_array.empty? constants = string_array.map! do |class_name| const = ::NewRelic::LanguageSupport.constantize(class_name) NewRelic::Agent.logger.warn("Ignoring invalid constant '#{class_name}' in #{string_array}") unless const const end constants.compact! constants end |
.convert_to_regexp_list(string_array) ⇒ Object
203 204 205 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 203 def self.convert_to_regexp_list(string_array) string_array.map { |value| /#{value}/ } end |
.default_for(key) ⇒ Object
69 70 71 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 69 def self.default_for(key) value_from_defaults(key, :default) end |
.default_settings(key) ⇒ Object
57 58 59 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 57 def self.default_settings(key) ::NewRelic::Agent::Configuration::DEFAULTS[key] end |
.dispatcher ⇒ Object
169 170 171 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 169 def self.dispatcher proc { NewRelic::Control.instance.local_env.discovered_dispatcher } end |
.framework ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 121 def self.framework proc { case when defined?(::NewRelic::TEST) then :test when defined?(::Rails::VERSION) case Rails::VERSION::MAJOR when 3 :rails3 when 4..8 :rails_notifications else ::NewRelic::Agent.logger.warn("Detected untested Rails version #{Rails::VERSION::STRING}") :rails_notifications end when defined?(::Padrino) && defined?(::Padrino::PathRouter::Router) then :padrino when defined?(::Sinatra) && defined?(::Sinatra::Base) then :sinatra when defined?(::Roda) then :roda when defined?(::Grape) then :grape when defined?(::NewRelic::IA) then :external else :ruby end } end |
.host ⇒ Object
192 193 194 195 196 197 198 199 200 201 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 192 def self.host proc do regex = /\A(?<identifier>.+?)x/ if matches = regex.match(String(NewRelic::Agent.config[:license_key])) "collector.#{matches['identifier']}.nr-data.net" else 'collector.newrelic.com' end end end |
.profiling_available ⇒ Object
181 182 183 184 185 186 187 188 189 190 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 181 def self.profiling_available proc { begin require 'ruby-prof' true rescue LoadError false end } end |
.thread_profiler_enabled ⇒ Object
173 174 175 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 173 def self.thread_profiler_enabled proc { NewRelic::Agent::Threading::BacktraceService.is_supported? } end |
.transaction_tracer_transaction_threshold ⇒ Object
177 178 179 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 177 def self.transaction_tracer_transaction_threshold proc { NewRelic::Agent.config[:apdex_t] * 4 } end |
.transform_for(key) ⇒ Object
73 74 75 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 73 def self.transform_for(key) value_from_defaults(key, :transform) end |
.value_from_defaults(key, subkey) ⇒ Object
61 62 63 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 61 def self.value_from_defaults(key, subkey) default_settings(key)&.send(:[], subkey) end |
Instance Method Details
#default_values ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 49 def default_values result = {} ::NewRelic::Agent::Configuration::DEFAULTS.each do |key, value| result[key] = value[:default] end result end |