newrelic_rpm 3.5.4.35.beta → 3.5.5.38
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +42 -0
- data/GUIDELINES_FOR_CONTRIBUTING.md +3 -0
- data/Rakefile +8 -0
- data/bin/mongrel_rpm +1 -1
- data/init.rb +1 -8
- data/lib/new_relic/agent.rb +11 -13
- data/lib/new_relic/agent/agent.rb +89 -110
- data/lib/new_relic/agent/agent_logger.rb +165 -0
- data/lib/new_relic/agent/audit_logger.rb +72 -0
- data/lib/new_relic/agent/beacon_configuration.rb +4 -4
- data/lib/new_relic/agent/browser_monitoring.rb +13 -7
- data/lib/new_relic/agent/busy_calculator.rb +2 -2
- data/lib/new_relic/agent/configuration.rb +25 -0
- data/lib/new_relic/agent/configuration/defaults.rb +45 -8
- data/lib/new_relic/agent/configuration/environment_source.rb +8 -15
- data/lib/new_relic/agent/configuration/manager.rb +22 -2
- data/lib/new_relic/agent/configuration/mask_defaults.rb +10 -0
- data/lib/new_relic/agent/configuration/yaml_source.rb +4 -2
- data/lib/new_relic/agent/cross_process_monitoring.rb +43 -0
- data/lib/new_relic/agent/database.rb +2 -4
- data/lib/new_relic/agent/error_collector.rb +4 -9
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_record.rb +1 -1
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +1 -1
- data/lib/new_relic/agent/instrumentation/authlogic.rb +1 -1
- data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +41 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +7 -7
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +1 -1
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +1 -1
- data/lib/new_relic/agent/instrumentation/memcache.rb +4 -4
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +1 -1
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +1 -1
- data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +1 -1
- data/lib/new_relic/agent/instrumentation/net.rb +1 -1
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +2 -2
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +4 -4
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +3 -3
- data/lib/new_relic/agent/instrumentation/rails3/errors.rb +1 -1
- data/lib/new_relic/agent/instrumentation/resque.rb +3 -2
- data/lib/new_relic/agent/instrumentation/sinatra.rb +1 -1
- data/lib/new_relic/agent/instrumentation/sunspot.rb +1 -1
- data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +2 -2
- data/lib/new_relic/agent/method_tracer.rb +6 -8
- data/lib/new_relic/agent/new_relic_service.rb +94 -106
- data/lib/new_relic/agent/pipe_channel_manager.rb +1 -1
- data/lib/new_relic/agent/samplers/memory_sampler.rb +4 -6
- data/lib/new_relic/agent/sql_sampler.rb +3 -18
- data/lib/new_relic/agent/stats_engine.rb +0 -5
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +3 -3
- data/lib/new_relic/agent/stats_engine/samplers.rb +2 -4
- data/lib/new_relic/agent/thread.rb +8 -3
- data/lib/new_relic/agent/thread_profiler.rb +38 -27
- data/lib/new_relic/agent/transaction_info.rb +1 -1
- data/lib/new_relic/agent/transaction_sample_builder.rb +2 -3
- data/lib/new_relic/agent/transaction_sampler.rb +3 -7
- data/lib/new_relic/agent/worker_loop.rb +3 -11
- data/lib/new_relic/control.rb +0 -2
- data/lib/new_relic/control/class_methods.rb +8 -2
- data/lib/new_relic/control/frameworks/merb.rb +0 -6
- data/lib/new_relic/control/frameworks/rails.rb +8 -29
- data/lib/new_relic/control/frameworks/rails3.rb +8 -20
- data/lib/new_relic/control/frameworks/rails4.rb +23 -0
- data/lib/new_relic/control/frameworks/ruby.rb +1 -22
- data/lib/new_relic/control/instance_methods.rb +12 -34
- data/lib/new_relic/control/instrumentation.rb +7 -12
- data/lib/new_relic/control/server_methods.rb +5 -8
- data/lib/new_relic/delayed_job_injection.rb +1 -1
- data/lib/new_relic/local_environment.rb +30 -64
- data/lib/new_relic/metric_data.rb +1 -1
- data/lib/new_relic/metric_spec.rb +1 -1
- data/lib/new_relic/noticed_error.rb +1 -1
- data/lib/new_relic/rack/browser_monitoring.rb +5 -5
- data/lib/new_relic/stats.rb +9 -7
- data/lib/new_relic/transaction_sample.rb +2 -7
- data/lib/new_relic/version.rb +1 -1
- data/lib/newrelic_rpm.rb +1 -1
- data/newrelic_rpm.gemspec.erb +15 -17
- data/test/config/newrelic.yml +1 -1
- data/test/config/test_control.rb +18 -18
- data/test/fixtures/gemspec_no_build.rb +0 -2
- data/test/fixtures/gemspec_with_build.rb +0 -2
- data/test/fixtures/gemspec_with_build_and_stage.rb +0 -2
- data/test/multiverse/README.md +3 -8
- data/test/multiverse/suites/agent_only/Envfile +1 -0
- data/test/multiverse/suites/agent_only/audit_log_test.rb +99 -0
- data/test/multiverse/suites/agent_only/marshaling_test.rb +1 -1
- data/test/multiverse/suites/config_file_loading/Envfile +7 -0
- data/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +106 -0
- data/test/multiverse/suites/logging/Envfile +4 -0
- data/test/multiverse/suites/logging/config/newrelic.yml +22 -0
- data/test/multiverse/suites/logging/logging_test.rb +143 -0
- data/test/multiverse/suites/no_load/config/newrelic.yml +1 -2
- data/test/multiverse/suites/rum_auto_instrumentation/sanity_test.rb +0 -13
- data/test/new_relic/agent/agent/connect_test.rb +30 -92
- data/test/new_relic/agent/agent/start_test.rb +4 -84
- data/test/new_relic/agent/agent/start_worker_thread_test.rb +8 -43
- data/test/new_relic/agent/agent_logger_test.rb +153 -0
- data/test/new_relic/agent/agent_test.rb +10 -9
- data/test/new_relic/agent/audit_logger_test.rb +105 -0
- data/test/new_relic/agent/browser_monitoring_test.rb +2 -1
- data/test/new_relic/agent/busy_calculator_test.rb +7 -0
- data/test/new_relic/agent/configuration/environment_source_test.rb +25 -20
- data/test/new_relic/agent/configuration/manager_test.rb +59 -4
- data/test/new_relic/agent/configuration/yaml_source_test.rb +20 -1
- data/test/new_relic/agent/cross_process_monitoring_test.rb +77 -0
- data/test/new_relic/agent/database_test.rb +0 -11
- data/test/new_relic/agent/error_collector/notice_error_test.rb +1 -3
- data/test/new_relic/agent/error_collector_test.rb +11 -7
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +39 -19
- data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +39 -0
- data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +1 -1
- data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +0 -6
- data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +3 -15
- data/test/new_relic/agent/new_relic_service_test.rb +48 -8
- data/test/new_relic/agent/pipe_channel_manager_test.rb +1 -1
- data/test/new_relic/agent/sql_sampler_test.rb +1 -1
- data/test/new_relic/agent/thread_profiler_test.rb +46 -45
- data/test/new_relic/agent/thread_test.rb +13 -0
- data/test/new_relic/agent/transaction_sample_builder_test.rb +1 -1
- data/test/new_relic/agent/worker_loop_test.rb +4 -9
- data/test/new_relic/agent_test.rb +6 -9
- data/test/new_relic/control/class_methods_test.rb +0 -18
- data/test/new_relic/control_test.rb +6 -9
- data/test/new_relic/dispatcher_test.rb +54 -0
- data/test/new_relic/fake_collector.rb +15 -14
- data/test/new_relic/fake_service.rb +4 -1
- data/test/new_relic/fakes_sending_data.rb +30 -0
- data/test/new_relic/framework_test.rb +53 -0
- data/test/new_relic/local_environment_test.rb +5 -2
- data/test/new_relic/rack/browser_monitoring_test.rb +2 -1
- data/test/new_relic/rack/developer_mode_test.rb +1 -1
- data/test/new_relic/stats_test.rb +10 -0
- data/test/new_relic/transaction_sample_test.rb +2 -2
- data/test/script/ci.sh +1 -1
- data/test/test_helper.rb +23 -0
- data/ui/views/newrelic/file/images/arrow-close.png +0 -0
- data/ui/views/newrelic/file/images/arrow-open.png +0 -0
- data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
- data/ui/views/newrelic/file/images/file_icon.png +0 -0
- data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
- metadata +47 -41
- data/InstallationNotes.md +0 -15
- data/lib/new_relic/control/logging_methods.rb +0 -125
- data/test/multiverse/Rakefile +0 -17
- data/test/multiverse/suites/rum_auto_instrumentation/problem_response.html +0 -422
- data/test/new_relic/control/logging_methods_test.rb +0 -211
@@ -11,12 +11,6 @@ module NewRelic
|
|
11
11
|
::Merb.root
|
12
12
|
end
|
13
13
|
|
14
|
-
def to_stdout(msg)
|
15
|
-
Merb.logger.info("NewRelic ~ " + msg)
|
16
|
-
rescue => e
|
17
|
-
STDOUT.puts "NewRelic ~ " + msg
|
18
|
-
end
|
19
|
-
|
20
14
|
def init_config options={}
|
21
15
|
::Merb::Plugins.add_rakefiles File.join(newrelic_root,"lib/tasks/all.rb")
|
22
16
|
|
@@ -17,9 +17,6 @@ module NewRelic
|
|
17
17
|
super
|
18
18
|
end
|
19
19
|
end
|
20
|
-
def logger
|
21
|
-
::RAILS_DEFAULT_LOGGER
|
22
|
-
end
|
23
20
|
|
24
21
|
def rails_config
|
25
22
|
if defined?(::Rails) && ::Rails.respond_to?(:configuration)
|
@@ -46,9 +43,9 @@ module NewRelic
|
|
46
43
|
if !Agent.config[:agent_enabled]
|
47
44
|
# Might not be running if it does not think mongrel, thin, passenger, etc
|
48
45
|
# is running, if it thinks it's a rake task, or if the agent_enabled is false.
|
49
|
-
|
46
|
+
::NewRelic::Agent.logger.info("New Relic Agent not running.")
|
50
47
|
else
|
51
|
-
|
48
|
+
::NewRelic::Agent.logger.info("Starting the New Relic Agent.")
|
52
49
|
install_developer_mode rails_config if Agent.config[:developer_mode]
|
53
50
|
install_browser_monitoring(rails_config)
|
54
51
|
end
|
@@ -61,9 +58,9 @@ module NewRelic
|
|
61
58
|
begin
|
62
59
|
require 'new_relic/rack/browser_monitoring'
|
63
60
|
config.middleware.use NewRelic::Rack::BrowserMonitoring
|
64
|
-
|
61
|
+
::NewRelic::Agent.logger.debug("Installed New Relic Browser Monitoring middleware")
|
65
62
|
rescue => e
|
66
|
-
|
63
|
+
::NewRelic::Agent.logger.warn("Error installing New Relic Browser Monitoring middleware: #{e.inspect}")
|
67
64
|
end
|
68
65
|
end
|
69
66
|
|
@@ -79,33 +76,15 @@ module NewRelic
|
|
79
76
|
# a webserver process
|
80
77
|
if @local_env.dispatcher_instance_id
|
81
78
|
port = @local_env.dispatcher_instance_id.to_s =~ /^\d+/ ? ":#{local_env.dispatcher_instance_id}" : ":port"
|
82
|
-
|
83
|
-
|
79
|
+
::NewRelic::Agent.logger.debug("NewRelic Agent Developer Mode enabled.")
|
80
|
+
::NewRelic::Agent.logger.debug("To view performance information, go to http://localhost#{port}/newrelic")
|
84
81
|
end
|
85
82
|
rescue => e
|
86
|
-
|
83
|
+
::NewRelic::Agent.logger.warn("Error installing New Relic Developer Mode: #{e.inspect}")
|
87
84
|
end
|
88
85
|
elsif rails_config
|
89
|
-
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def log!(msg, level=:info)
|
94
|
-
if should_log?
|
95
|
-
logger = ::Rails.respond_to?(:logger) ? ::Rails.logger : ::RAILS_DEFAULT_LOGGER
|
96
|
-
logger.send(level, msg)
|
97
|
-
else
|
98
|
-
super
|
86
|
+
::NewRelic::Agent.logger.warn("Developer mode not available for Rails versions prior to 2.2")
|
99
87
|
end
|
100
|
-
rescue => e
|
101
|
-
super
|
102
|
-
end
|
103
|
-
|
104
|
-
def to_stdout(message)
|
105
|
-
logger = ::Rails.respond_to?(:logger) ? ::Rails.logger : ::RAILS_DEFAULT_LOGGER
|
106
|
-
logger.info(message)
|
107
|
-
rescue => e
|
108
|
-
super
|
109
88
|
end
|
110
89
|
|
111
90
|
def rails_version
|
@@ -13,7 +13,7 @@ module NewRelic
|
|
13
13
|
def env
|
14
14
|
@env ||= ::Rails.env.to_s
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
# Rails can return an empty string from this method, causing
|
18
18
|
# the agent not to start even when it is properly in a rails 3
|
19
19
|
# application, so we test the value to make sure it actually
|
@@ -27,34 +27,18 @@ module NewRelic
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
def logger
|
31
|
-
::Rails.logger
|
32
|
-
end
|
33
|
-
|
34
30
|
def init_config(options={})
|
35
31
|
super
|
36
32
|
if Agent.config[:agent_enabled] && Agent.config[:'error_collector.enabled']
|
37
33
|
if !rails_config.middleware.respond_to?(:include?) ||
|
38
34
|
!rails_config.middleware.include?(NewRelic::Rack::ErrorCollector)
|
39
|
-
|
35
|
+
add_error_collector_middleware
|
40
36
|
end
|
41
37
|
end
|
42
38
|
end
|
43
39
|
|
44
|
-
def
|
45
|
-
|
46
|
-
logger.send(level, msg)
|
47
|
-
else
|
48
|
-
super
|
49
|
-
end
|
50
|
-
rescue => e
|
51
|
-
super
|
52
|
-
end
|
53
|
-
|
54
|
-
def to_stdout(msg)
|
55
|
-
logger.info(msg)
|
56
|
-
rescue
|
57
|
-
super
|
40
|
+
def add_error_collector_middleware
|
41
|
+
rails_config.middleware.use NewRelic::Rack::ErrorCollector
|
58
42
|
end
|
59
43
|
|
60
44
|
def vendor_root
|
@@ -77,6 +61,10 @@ module NewRelic
|
|
77
61
|
local_env.append_gem_list do
|
78
62
|
bundler_gem_list
|
79
63
|
end
|
64
|
+
append_plugin_list
|
65
|
+
end
|
66
|
+
|
67
|
+
def append_plugin_list
|
80
68
|
local_env.append_plugin_list { ::Rails.configuration.plugins.to_a }
|
81
69
|
end
|
82
70
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'new_relic/control/frameworks/rails3'
|
2
|
+
require 'new_relic/rack/error_collector'
|
3
|
+
module NewRelic
|
4
|
+
class Control
|
5
|
+
module Frameworks
|
6
|
+
class Rails4 < NewRelic::Control::Frameworks::Rails3
|
7
|
+
def rails_gem_list
|
8
|
+
Bundler.rubygems.all_specs.map do |gem|
|
9
|
+
"#{gem.name} (#{gem.version})"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def add_error_collector_middleware
|
14
|
+
# rails_config.middleware.use NewRelic::Rack::ErrorCollector
|
15
|
+
end
|
16
|
+
|
17
|
+
def append_plugin_list
|
18
|
+
# Rails 4 does not allow plugins
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -2,36 +2,15 @@ module NewRelic
|
|
2
2
|
class Control
|
3
3
|
module Frameworks
|
4
4
|
# A control used when no framework is detected - the default.
|
5
|
-
# Looks for a newrelic.yml file in several locations including
|
6
|
-
# ./, ./config, $HOME/.newrelic and $HOME/. It loads the
|
7
|
-
# settings from the newrelic.yml section based on the value of
|
8
|
-
# RUBY_ENV or RAILS_ENV.
|
9
5
|
class Ruby < NewRelic::Control
|
10
6
|
|
11
7
|
def env
|
12
8
|
@env ||= ENV['RUBY_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
|
13
9
|
end
|
10
|
+
|
14
11
|
def root
|
15
12
|
@root ||= ENV['APP_ROOT'] || '.'
|
16
13
|
end
|
17
|
-
# Check a sequence of file locations for newrelic.yml
|
18
|
-
def config_file
|
19
|
-
files = []
|
20
|
-
files << File.join(root,"config","newrelic.yml")
|
21
|
-
files << File.join(root,"newrelic.yml")
|
22
|
-
if ENV["HOME"]
|
23
|
-
files << File.join(ENV["HOME"], ".newrelic", "newrelic.yml")
|
24
|
-
files << File.join(ENV["HOME"], "newrelic.yml")
|
25
|
-
end
|
26
|
-
files << File.expand_path(ENV["NRCONFIG"]) if ENV["NRCONFIG"]
|
27
|
-
files.each do |file|
|
28
|
-
return File.expand_path(file) if File.exists? file
|
29
|
-
end
|
30
|
-
return File.expand_path(files.first)
|
31
|
-
end
|
32
|
-
def to_stdout(msg)
|
33
|
-
STDOUT.puts msg
|
34
|
-
end
|
35
14
|
|
36
15
|
def init_config(options={})
|
37
16
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'new_relic/language_support'
|
2
|
+
require 'new_relic/agent/agent_logger'
|
2
3
|
|
3
4
|
module NewRelic
|
4
5
|
class Control
|
@@ -19,7 +20,6 @@ module NewRelic
|
|
19
20
|
# machine-dependent information useful in debugging
|
20
21
|
attr_reader :local_env
|
21
22
|
|
22
|
-
|
23
23
|
# Initialize the plugin/gem and start the agent. This does the
|
24
24
|
# necessary configuration based on the framework environment and
|
25
25
|
# determines whether or not to start the agent. If the agent is
|
@@ -44,34 +44,19 @@ module NewRelic
|
|
44
44
|
# init_config({}) which is called one or more times.
|
45
45
|
#
|
46
46
|
def init_plugin(options={})
|
47
|
-
|
48
|
-
|
49
|
-
yaml = Agent::Configuration::YamlSource.new(path, env)
|
50
|
-
Agent.config.replace_or_add_config(yaml, 1)
|
51
|
-
rescue ScriptError, StandardError => e
|
52
|
-
# Why do we need to do this?
|
53
|
-
new_err = e.class.new("Error reading newrelic.yml file: #{e}")
|
54
|
-
new_err.set_backtrace(e.backtrace)
|
55
|
-
raise new_err
|
56
|
-
end
|
47
|
+
yaml = Agent::Configuration::YamlSource.new(@config_file_path, options[:env] || env)
|
48
|
+
Agent.config.replace_or_add_config(yaml, 1)
|
57
49
|
|
58
50
|
Agent.config.replace_or_add_config(Agent::Configuration::ManualSource.new(options), 1)
|
59
|
-
|
60
|
-
|
51
|
+
|
52
|
+
::NewRelic::Agent.logger = NewRelic::Agent::AgentLogger.new(Agent.config, root, options.delete(:log))
|
61
53
|
|
62
54
|
# Merge the stringified options into the config as overrides:
|
63
|
-
logger_override = options.delete(:log)
|
64
55
|
environment_name = options.delete(:env) and self.env = environment_name
|
65
|
-
dispatcher = options.delete(:dispatcher) and @local_env.dispatcher = dispatcher
|
66
56
|
dispatcher_instance_id = options.delete(:dispatcher_instance_id) and @local_env.dispatcher_instance_id = dispatcher_instance_id
|
67
57
|
|
68
58
|
NewRelic::Agent::PipeChannelManager.listener.start if options.delete(:start_channel_listener)
|
69
59
|
|
70
|
-
if logger_override
|
71
|
-
@log = logger_override
|
72
|
-
# Try to grab the log filename
|
73
|
-
@log_file = @log.instance_eval { @logdev.filename rescue nil }
|
74
|
-
end
|
75
60
|
# An artifact of earlier implementation, we put both #add_method_tracer and #trace_execution
|
76
61
|
# methods in the module methods.
|
77
62
|
Module.send :include, NewRelic::Agent::MethodTracer::ClassMethods
|
@@ -79,10 +64,9 @@ module NewRelic
|
|
79
64
|
init_config(options)
|
80
65
|
NewRelic::Agent.agent = NewRelic::Agent::Agent.instance
|
81
66
|
if Agent.config[:agent_enabled] && !NewRelic::Agent.instance.started?
|
82
|
-
setup_log unless logger_override
|
83
67
|
start_agent
|
84
68
|
install_instrumentation
|
85
|
-
load_samplers unless Agent.config[
|
69
|
+
load_samplers unless Agent.config[:disable_samplers]
|
86
70
|
local_env.gather_environment_info
|
87
71
|
append_environment_info
|
88
72
|
elsif !Agent.config[:agent_enabled]
|
@@ -95,14 +79,12 @@ module NewRelic
|
|
95
79
|
NewRelic::Agent.agent.start
|
96
80
|
end
|
97
81
|
|
98
|
-
# Asks the LocalEnvironment instance which framework should be loaded
|
99
82
|
def app
|
100
|
-
|
83
|
+
Agent.config[:framework]
|
101
84
|
end
|
102
|
-
alias framework app
|
103
85
|
|
104
|
-
def
|
105
|
-
|
86
|
+
def framework
|
87
|
+
Agent.config[:framework]
|
106
88
|
end
|
107
89
|
|
108
90
|
# for backward compatibility with the old config interface
|
@@ -111,7 +93,7 @@ module NewRelic
|
|
111
93
|
end
|
112
94
|
|
113
95
|
def settings
|
114
|
-
NewRelic::Agent.config.
|
96
|
+
NewRelic::Agent.config.reported_config
|
115
97
|
end
|
116
98
|
|
117
99
|
def dispatcher
|
@@ -137,15 +119,11 @@ module NewRelic
|
|
137
119
|
end
|
138
120
|
end
|
139
121
|
|
140
|
-
# path to the config file, defaults to the "#{root}/config/newrelic.yml"
|
141
|
-
def config_file
|
142
|
-
File.expand_path(File.join(root,"config","newrelic.yml"))
|
143
|
-
end
|
144
122
|
|
145
|
-
def initialize
|
123
|
+
def initialize(local_env, config_file_override=nil)
|
146
124
|
@local_env = local_env
|
147
125
|
@instrumentation_files = []
|
148
|
-
@
|
126
|
+
@config_file_path = config_file_override || Agent.config[:config_path]
|
149
127
|
end
|
150
128
|
|
151
129
|
def root
|
@@ -9,17 +9,12 @@ module NewRelic
|
|
9
9
|
# This requires the files within a rescue block, so that any
|
10
10
|
# errors within instrumentation files do not affect the overall
|
11
11
|
# agent or application in which it runs.
|
12
|
-
#
|
13
|
-
# Logs at debug level for each file loaded, and logs errors in
|
14
|
-
# file loading at error level
|
15
12
|
def load_instrumentation_files pattern
|
16
13
|
Dir.glob(pattern) do |file|
|
17
14
|
begin
|
18
|
-
log.debug "Processing instrumentation file '#{file}'"
|
19
15
|
require file.to_s
|
20
16
|
rescue => e
|
21
|
-
|
22
|
-
log.debug e.backtrace.join("\n")
|
17
|
+
::NewRelic::Agent.logger.warn "Error loading instrumentation file '#{file}':", e
|
23
18
|
end
|
24
19
|
end
|
25
20
|
end
|
@@ -60,19 +55,19 @@ module NewRelic
|
|
60
55
|
agent = NewRelic::Agent.instance
|
61
56
|
NewRelic::Agent::Sampler.sampler_classes.each do | subclass |
|
62
57
|
begin
|
63
|
-
|
58
|
+
::NewRelic::Agent.logger.debug "#{subclass.name} not supported on this platform." and next if not subclass.supported_on_this_platform?
|
64
59
|
sampler = subclass.new
|
65
60
|
if subclass.use_harvest_sampler?
|
66
61
|
agent.stats_engine.add_harvest_sampler sampler
|
67
|
-
|
62
|
+
::NewRelic::Agent.logger.debug "Registered #{subclass.name} for harvest time sampling"
|
68
63
|
else
|
69
64
|
agent.stats_engine.add_sampler sampler
|
70
|
-
|
65
|
+
::NewRelic::Agent.logger.debug "Registered #{subclass.name} for periodic sampling"
|
71
66
|
end
|
72
67
|
rescue NewRelic::Agent::Sampler::Unsupported => e
|
73
|
-
|
68
|
+
::NewRelic::Agent.logger.info "#{subclass} sampler not available: #{e}"
|
74
69
|
rescue => e
|
75
|
-
|
70
|
+
::NewRelic::Agent.logger.error "Error registering sampler:", e
|
76
71
|
end
|
77
72
|
end
|
78
73
|
end
|
@@ -92,7 +87,7 @@ module NewRelic
|
|
92
87
|
File.join(instrumentation_path, app.to_s, '*.rb')
|
93
88
|
@instrumentation_files.each { | pattern | load_instrumentation_files pattern }
|
94
89
|
DependencyDetection.detect!
|
95
|
-
|
90
|
+
::NewRelic::Agent.logger.info "Finished instrumentation"
|
96
91
|
end
|
97
92
|
end
|
98
93
|
include Instrumentation
|
@@ -52,9 +52,7 @@ module NewRelic
|
|
52
52
|
return nil if host.nil? || host.downcase == "localhost"
|
53
53
|
ip = resolve_ip_address(host)
|
54
54
|
|
55
|
-
|
56
|
-
# should bring it back when logging / startup is fixed
|
57
|
-
# log.info "Resolved #{host} to #{ip}"
|
55
|
+
::NewRelic::Agent.logger.debug "Resolved #{host} to #{ip}"
|
58
56
|
ip
|
59
57
|
end
|
60
58
|
|
@@ -65,13 +63,12 @@ module NewRelic
|
|
65
63
|
def resolve_ip_address(host)
|
66
64
|
Resolv.getaddress(host)
|
67
65
|
rescue => e
|
68
|
-
|
69
|
-
log.debug(e.backtrace.join("\n "))
|
66
|
+
::NewRelic::Agent.logger.warn("DNS Error caching IP address:", e)
|
70
67
|
begin
|
71
|
-
|
68
|
+
::NewRelic::Agent.logger.debug("Trying native DNS lookup since Resolv failed")
|
72
69
|
IPSocket.getaddress(host)
|
73
70
|
rescue => e
|
74
|
-
|
71
|
+
::NewRelic::Agent.logger.error("Could not look up server address: #{e}")
|
75
72
|
nil
|
76
73
|
end
|
77
74
|
end
|
@@ -95,7 +92,7 @@ module NewRelic
|
|
95
92
|
http_class = Net::HTTP::Proxy(proxy_server.name, proxy_server.port,
|
96
93
|
proxy_server.user, proxy_server.password)
|
97
94
|
http = http_class.new(host.ip || host.name, host.port)
|
98
|
-
|
95
|
+
::NewRelic::Agent.logger.debug("Http Connection opened to #{host.ip||host.name}:#{host.port}")
|
99
96
|
if Agent.config[:ssl]
|
100
97
|
http.use_ssl = true
|
101
98
|
if Agent.config[:verify_certificate]
|
@@ -20,7 +20,7 @@ DependencyDetection.defer do
|
|
20
20
|
|
21
21
|
executes do
|
22
22
|
if NewRelic::Agent.respond_to?(:logger)
|
23
|
-
NewRelic::Agent.logger.
|
23
|
+
::NewRelic::Agent.logger.info 'Installing DelayedJob instrumentation hooks'
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -5,7 +5,6 @@ module NewRelic
|
|
5
5
|
# An instance of LocalEnvironment is responsible for determining
|
6
6
|
# three things:
|
7
7
|
#
|
8
|
-
# * Framework - :rails, :rails3, :merb, :ruby, :external, :test
|
9
8
|
# * Dispatcher - A supported dispatcher, or nil (:mongrel, :thin, :passenger, :webrick, etc)
|
10
9
|
# * Dispatcher Instance ID, which distinguishes agents on a single host from each other
|
11
10
|
#
|
@@ -15,15 +14,16 @@ module NewRelic
|
|
15
14
|
# NewRelic::LocalEnvironment should be accessed through NewRelic::Control#env (via the NewRelic::Control singleton).
|
16
15
|
class LocalEnvironment
|
17
16
|
# mongrel, thin, webrick, or possibly nil
|
18
|
-
|
17
|
+
def discovered_dispatcher
|
18
|
+
discover_dispatcher unless @discovered_dispatcher
|
19
|
+
@discovered_dispatcher
|
20
|
+
end
|
21
|
+
|
19
22
|
# used to distinguish instances of a dispatcher from each other, may be nil
|
20
23
|
attr_writer :dispatcher_instance_id
|
21
|
-
# rails, rails3, merb, external, ruby, test, etc
|
22
|
-
attr_accessor :framework
|
23
24
|
# The number of cpus, if detected, or nil - many platforms do not
|
24
25
|
# support this :(
|
25
26
|
attr_reader :processors
|
26
|
-
alias environment dispatcher
|
27
27
|
|
28
28
|
def initialize
|
29
29
|
# Extend self with any any submodules of LocalEnvironment. These can override
|
@@ -33,9 +33,7 @@ module NewRelic
|
|
33
33
|
self.extend mod if mod.instance_of? Module
|
34
34
|
end
|
35
35
|
|
36
|
-
discover_framework
|
37
36
|
discover_dispatcher
|
38
|
-
@dispatcher = nil if @dispatcher == :none
|
39
37
|
@gems = Set.new
|
40
38
|
@plugins = Set.new
|
41
39
|
@config = Hash.new
|
@@ -48,9 +46,8 @@ module NewRelic
|
|
48
46
|
def append_environment_value(name, value = nil)
|
49
47
|
value = yield if block_given?
|
50
48
|
@config[name] = value if value
|
51
|
-
rescue
|
52
|
-
|
53
|
-
raise if @framework == :test
|
49
|
+
rescue => e
|
50
|
+
Agent.logger.error e
|
54
51
|
end
|
55
52
|
|
56
53
|
# yields to the block and appends the returned value to the list
|
@@ -58,24 +55,22 @@ module NewRelic
|
|
58
55
|
def append_gem_list
|
59
56
|
@gems += yield
|
60
57
|
rescue => e
|
61
|
-
|
62
|
-
raise if @framework == :test
|
58
|
+
Agent.logger.error e
|
63
59
|
end
|
64
60
|
|
65
61
|
# yields to the block and appends the returned value to the list
|
66
62
|
# of plugins - this catches errors that might be raised in the block
|
67
63
|
def append_plugin_list
|
68
64
|
@plugins += yield
|
69
|
-
rescue
|
70
|
-
|
71
|
-
raise if @framework == :test
|
65
|
+
rescue => e
|
66
|
+
Agent.logger.error e
|
72
67
|
end
|
73
68
|
|
74
69
|
# An instance id pulled from either @dispatcher_instance_id or by
|
75
70
|
# splitting out the first part of the running file
|
76
71
|
def dispatcher_instance_id
|
77
72
|
if @dispatcher_instance_id.nil?
|
78
|
-
if @
|
73
|
+
if @discovered_dispatcher.nil?
|
79
74
|
@dispatcher_instance_id = File.basename($0).split(".").first
|
80
75
|
end
|
81
76
|
end
|
@@ -122,7 +117,7 @@ module NewRelic
|
|
122
117
|
|
123
118
|
if processors == 0
|
124
119
|
processors = 1 # assume there is at least one processor
|
125
|
-
NewRelic::Agent.logger.warn("Cannot determine the number of processors in #{proc_file}")
|
120
|
+
::NewRelic::Agent.logger.warn("Cannot determine the number of processors in #{proc_file}")
|
126
121
|
end
|
127
122
|
processors
|
128
123
|
end
|
@@ -197,8 +192,8 @@ module NewRelic
|
|
197
192
|
# Collect base statistics about the environment and record them for
|
198
193
|
# comparison and change detection.
|
199
194
|
def gather_environment_info
|
200
|
-
append_environment_value 'Framework',
|
201
|
-
append_environment_value 'Dispatcher',
|
195
|
+
append_environment_value 'Framework', Agent.config[:framework].to_s
|
196
|
+
append_environment_value 'Dispatcher', Agent.config[:dispatcher].to_s if Agent.config[:dispatcher]
|
202
197
|
append_environment_value 'Dispatcher instance id', @dispatcher_instance_id if @dispatcher_instance_id
|
203
198
|
append_environment_value('Environment') { NewRelic::Control.instance.env }
|
204
199
|
|
@@ -244,47 +239,19 @@ module NewRelic
|
|
244
239
|
|
245
240
|
private
|
246
241
|
|
247
|
-
# Although you can override the
|
242
|
+
# Although you can override the dispatcher with NEWRELIC_DISPATCHER this
|
248
243
|
# is not advisable since it implies certain api's being available.
|
249
244
|
def discover_dispatcher
|
250
|
-
@dispatcher ||= ENV['NEWRELIC_DISPATCHER'] && ENV['NEWRELIC_DISPATCHER'].to_sym
|
251
|
-
@dispatcher ||= ENV['NEW_RELIC_DISPATCHER'] && ENV['NEW_RELIC_DISPATCHER'].to_sym
|
252
245
|
dispatchers = %w[passenger torquebox glassfish thin mongrel litespeed webrick fastcgi unicorn sinatra]
|
253
|
-
while dispatchers.any? && @
|
246
|
+
while dispatchers.any? && @discovered_dispatcher.nil?
|
254
247
|
send 'check_for_'+(dispatchers.shift)
|
255
248
|
end
|
256
249
|
end
|
257
250
|
|
258
|
-
def discover_framework
|
259
|
-
# Although you can override the framework with NEWRELIC_FRAMEWORK this
|
260
|
-
# is not advisable since it implies certain api's being available.
|
261
|
-
#
|
262
|
-
# Note that the odd defined? sequence is necessary to work around a bug in an older version
|
263
|
-
# of JRuby.
|
264
|
-
@framework ||= case
|
265
|
-
when ENV['NEWRELIC_FRAMEWORK'] then ENV['NEWRELIC_FRAMEWORK'].to_sym
|
266
|
-
when ENV['NEW_RELIC_FRAMEWORK'] then ENV['NEW_RELIC_FRAMEWORK'].to_sym
|
267
|
-
when defined?(::NewRelic::TEST) then :test
|
268
|
-
when defined?(::Merb) && defined?(::Merb::Plugins) then :merb
|
269
|
-
when defined?(::Rails) then check_rails_version
|
270
|
-
when defined?(::Sinatra) && defined?(::Sinatra::Base) then :sinatra
|
271
|
-
when defined?(::NewRelic::IA) then :external
|
272
|
-
else :ruby
|
273
|
-
end
|
274
|
-
end
|
275
|
-
|
276
|
-
def check_rails_version
|
277
|
-
if Rails::VERSION::MAJOR < 3
|
278
|
-
:rails
|
279
|
-
else
|
280
|
-
:rails3
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
251
|
def check_for_torquebox
|
285
252
|
return unless defined?(::JRuby) &&
|
286
253
|
( org.torquebox::TorqueBox rescue nil)
|
287
|
-
@
|
254
|
+
@discovered_dispatcher = :torquebox
|
288
255
|
end
|
289
256
|
|
290
257
|
def check_for_glassfish
|
@@ -292,12 +259,12 @@ module NewRelic
|
|
292
259
|
(((com.sun.grizzly.jruby.rack.DefaultRackApplicationFactory rescue nil) &&
|
293
260
|
defined?(com::sun::grizzly::jruby::rack::DefaultRackApplicationFactory)) ||
|
294
261
|
(jruby_rack? && defined?(::GlassFish::Server)))
|
295
|
-
@
|
262
|
+
@discovered_dispatcher = :glassfish
|
296
263
|
end
|
297
264
|
|
298
265
|
def check_for_trinidad
|
299
266
|
return unless defined?(::JRuby) && jruby_rack? && defined?(::Trinidad::Server)
|
300
|
-
@
|
267
|
+
@discovered_dispatcher = :trinidad
|
301
268
|
end
|
302
269
|
|
303
270
|
def jruby_rack?
|
@@ -307,7 +274,7 @@ module NewRelic
|
|
307
274
|
|
308
275
|
def check_for_webrick
|
309
276
|
return unless defined?(::WEBrick) && defined?(::WEBrick::VERSION)
|
310
|
-
@
|
277
|
+
@discovered_dispatcher = :webrick
|
311
278
|
if defined?(::OPTIONS) && OPTIONS.respond_to?(:fetch)
|
312
279
|
# OPTIONS is set by script/server
|
313
280
|
@dispatcher_instance_id = OPTIONS.fetch(:port)
|
@@ -317,13 +284,13 @@ module NewRelic
|
|
317
284
|
|
318
285
|
def check_for_fastcgi
|
319
286
|
return unless defined?(::FCGI)
|
320
|
-
@
|
287
|
+
@discovered_dispatcher = :fastcgi
|
321
288
|
end
|
322
289
|
|
323
290
|
# this case covers starting by mongrel_rails
|
324
291
|
def check_for_mongrel
|
325
292
|
return unless defined?(::Mongrel) && defined?(::Mongrel::HttpServer)
|
326
|
-
@
|
293
|
+
@discovered_dispatcher = :mongrel
|
327
294
|
|
328
295
|
# Get the port from the server if it's started
|
329
296
|
|
@@ -345,7 +312,7 @@ module NewRelic
|
|
345
312
|
def check_for_unicorn
|
346
313
|
if (defined?(::Unicorn) && defined?(::Unicorn::HttpServer)) && working_jruby?
|
347
314
|
v = find_class_in_object_space(::Unicorn::HttpServer)
|
348
|
-
@
|
315
|
+
@discovered_dispatcher = :unicorn if v
|
349
316
|
end
|
350
317
|
end
|
351
318
|
|
@@ -362,7 +329,7 @@ module NewRelic
|
|
362
329
|
$stderr.puts("Your Sinatra version is #{version}, we highly recommend upgrading to >=0.9.2")
|
363
330
|
end
|
364
331
|
|
365
|
-
@
|
332
|
+
@discovered_dispatcher = :sinatra
|
366
333
|
end
|
367
334
|
|
368
335
|
def check_for_thin
|
@@ -370,7 +337,7 @@ module NewRelic
|
|
370
337
|
# This case covers the thin web dispatcher
|
371
338
|
# Same issue as above- we assume only one instance per process
|
372
339
|
ObjectSpace.each_object(Thin::Server) do |thin_dispatcher|
|
373
|
-
@
|
340
|
+
@discovered_dispatcher = :thin
|
374
341
|
backend = thin_dispatcher.backend
|
375
342
|
# We need a way to uniquely identify and distinguish agents. The port
|
376
343
|
# works for this. When using sockets, use the socket file name.
|
@@ -383,21 +350,21 @@ module NewRelic
|
|
383
350
|
end
|
384
351
|
end # each thin instance
|
385
352
|
end
|
386
|
-
if defined?(::Thin) && defined?(::Thin::VERSION) && !@
|
387
|
-
@
|
353
|
+
if defined?(::Thin) && defined?(::Thin::VERSION) && !@discovered_dispatcher
|
354
|
+
@discovered_dispatcher = :thin
|
388
355
|
@dispatcher_instance_id = default_port
|
389
356
|
end
|
390
357
|
end
|
391
358
|
|
392
359
|
def check_for_litespeed
|
393
360
|
if caller.pop =~ /fcgi-bin\/RailsRunner\.rb/
|
394
|
-
@
|
361
|
+
@discovered_dispatcher = :litespeed
|
395
362
|
end
|
396
363
|
end
|
397
364
|
|
398
365
|
def check_for_passenger
|
399
366
|
if defined?(::PhusionPassenger)
|
400
|
-
@
|
367
|
+
@discovered_dispatcher = :passenger
|
401
368
|
end
|
402
369
|
end
|
403
370
|
|
@@ -417,8 +384,7 @@ module NewRelic
|
|
417
384
|
# outputs a human-readable description
|
418
385
|
def to_s
|
419
386
|
s = "LocalEnvironment["
|
420
|
-
s << @
|
421
|
-
s << ";dispatcher=#{@dispatcher}" if @dispatcher
|
387
|
+
s << ";dispatcher=#{@discovered_dispatcher}" if @discovered_dispatcher
|
422
388
|
s << ";instance=#{@dispatcher_instance_id}" if @dispatcher_instance_id
|
423
389
|
s << "]"
|
424
390
|
end
|