class NewRelic::EnvironmentReport
The EnvironmentReport
is responsible for analyzing the application’s environment and generating the data for the Environment Report in New Relic’s interface.
It contains useful system information like Ruby version, OS, loaded gems, etc.
Additional logic can be registered by using the EnvironmentReport.report_on
hook.
Attributes
end reporting logic
Public Class Methods
Source
# File lib/new_relic/environment_report.rb, line 92 def initialize @data = self.class.registered_reporters.inject(Hash.new) do |data, (key, logic)| begin value = logic.call value ? record_value(data, key, value) : record_empty_value(key, value) rescue => e rescue_initialize(key, e) end data end end
Generate the report based on the class level logic.
Source
# File lib/new_relic/environment_report.rb, line 34 def self.registered_reporters @registered_reporters ||= Hash.new end
Source
# File lib/new_relic/environment_report.rb, line 39 def self.registered_reporters=(logic) @registered_reporters = logic end
allow the logic to be swapped out in tests
Source
# File lib/new_relic/environment_report.rb, line 30 def self.report_on(key, &block) registered_reporters[key] = block end
This is the main interface for registering logic that should be included in the Environment Report. For example:
EnvironmentReport.report_on
“Day of week” do
Time.now.strftime("%A")
end
The passed blocks will be run in EnvironmentReport
instances on initialize.
Errors raised in passed blocks will be handled and logged at debug, so it is safe to report on things that may not work in certain environments.
The blocks should only return strings or arrays full of strings. Falsey values will be ignored.
Public Instance Methods
Source
# File lib/new_relic/environment_report.rb, line 108 def []=(key, value) @data[key] = value end
Private Instance Methods
Source
# File lib/new_relic/environment_report.rb, line 125 def record_empty_value(key, value) Agent.logger.debug("EnvironmentReport ignoring value for #{key.inspect} which came back falsey: #{value.inspect}") Agent.record_metric('Supportability/EnvironmentReport/empty', 0.0) Agent.record_metric("Supportability/EnvironmentReport/empty/#{key}", 0.0) end
Source
# File lib/new_relic/environment_report.rb, line 118 def record_value(data, key, value) data[key] = value Agent.record_metric('Supportability/EnvironmentReport/success', 0.0) Agent.record_metric("Supportability/EnvironmentReport/success/#{key}", 0.0) end
Source
# File lib/new_relic/environment_report.rb, line 131 def rescue_initialize(key, exception) Agent.logger.debug("EnvironmentReport failed to retrieve value for #{key.inspect}: #{exception}") Agent.record_metric('Supportability/EnvironmentReport/error', 0.0) Agent.record_metric("Supportability/EnvironmentReport/error/#{key}", 0.0) end