ghazel-newrelic_rpm 3.4.0.2 → 3.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (231) hide show
  1. data/.gitignore +21 -0
  2. data/.project +23 -0
  3. data/.travis.yml +9 -0
  4. data/CHANGELOG +180 -1
  5. data/GUIDELINES_FOR_CONTRIBUTING.md +73 -0
  6. data/Gemfile +16 -0
  7. data/InstallationNotes.md +15 -0
  8. data/LICENSE +1 -1
  9. data/{README.rdoc → README.md} +71 -55
  10. data/Rakefile +54 -0
  11. data/config.dot +290 -0
  12. data/config/database.yml +5 -0
  13. data/init.rb +38 -0
  14. data/lib/new_relic/agent.rb +9 -4
  15. data/lib/new_relic/agent/agent.rb +189 -230
  16. data/lib/new_relic/agent/beacon_configuration.rb +34 -48
  17. data/lib/new_relic/agent/browser_monitoring.rb +108 -61
  18. data/lib/new_relic/agent/busy_calculator.rb +12 -4
  19. data/lib/new_relic/agent/configuration.rb +49 -0
  20. data/lib/new_relic/agent/configuration/defaults.rb +89 -0
  21. data/lib/new_relic/agent/configuration/environment_source.rb +56 -0
  22. data/lib/new_relic/agent/configuration/manager.rb +116 -0
  23. data/lib/new_relic/agent/configuration/server_source.rb +27 -0
  24. data/lib/new_relic/agent/configuration/yaml_source.rb +61 -0
  25. data/lib/new_relic/agent/database.rb +37 -22
  26. data/lib/new_relic/agent/error_collector.rb +47 -43
  27. data/lib/new_relic/agent/instrumentation/active_record.rb +1 -5
  28. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +27 -6
  29. data/lib/new_relic/agent/instrumentation/data_mapper.rb +2 -10
  30. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +1 -1
  31. data/lib/new_relic/agent/instrumentation/memcache.rb +2 -2
  32. data/lib/new_relic/agent/instrumentation/metric_frame.rb +4 -14
  33. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +4 -18
  34. data/lib/new_relic/agent/instrumentation/rack.rb +1 -1
  35. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +3 -3
  36. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +2 -2
  37. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +5 -1
  38. data/lib/new_relic/agent/instrumentation/resque.rb +1 -1
  39. data/lib/new_relic/agent/instrumentation/sinatra.rb +14 -10
  40. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +4 -3
  41. data/lib/new_relic/agent/method_tracer.rb +5 -1
  42. data/lib/new_relic/agent/new_relic_service.rb +231 -61
  43. data/lib/new_relic/agent/pipe_channel_manager.rb +37 -23
  44. data/lib/new_relic/agent/pipe_service.rb +5 -1
  45. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +2 -5
  46. data/lib/new_relic/agent/samplers/memory_sampler.rb +2 -2
  47. data/lib/new_relic/agent/sql_sampler.rb +44 -68
  48. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +40 -24
  49. data/lib/new_relic/agent/stats_engine/metric_stats.rb +89 -14
  50. data/lib/new_relic/agent/stats_engine/samplers.rb +7 -3
  51. data/lib/new_relic/agent/stats_engine/transactions.rb +19 -11
  52. data/lib/new_relic/agent/thread.rb +27 -0
  53. data/lib/new_relic/agent/thread_profiler.rb +295 -0
  54. data/lib/new_relic/agent/transaction_info.rb +24 -4
  55. data/lib/new_relic/agent/transaction_sample_builder.rb +11 -11
  56. data/lib/new_relic/agent/transaction_sampler.rb +51 -61
  57. data/lib/new_relic/agent/worker_loop.rb +29 -15
  58. data/lib/new_relic/collection_helper.rb +1 -1
  59. data/lib/new_relic/commands/deployments.rb +19 -10
  60. data/lib/new_relic/control.rb +0 -1
  61. data/lib/new_relic/control/class_methods.rb +2 -3
  62. data/lib/new_relic/control/frameworks/rails.rb +24 -18
  63. data/lib/new_relic/control/frameworks/rails3.rb +18 -1
  64. data/lib/new_relic/control/frameworks/ruby.rb +2 -2
  65. data/lib/new_relic/control/instance_methods.rb +36 -53
  66. data/lib/new_relic/control/logging_methods.rb +5 -23
  67. data/lib/new_relic/control/server_methods.rb +11 -13
  68. data/lib/new_relic/delayed_job_injection.rb +1 -1
  69. data/lib/new_relic/helper.rb +13 -0
  70. data/lib/new_relic/language_support.rb +19 -22
  71. data/lib/new_relic/local_environment.rb +2 -3
  72. data/lib/new_relic/metric_data.rb +10 -2
  73. data/lib/new_relic/metric_spec.rb +6 -2
  74. data/lib/new_relic/noticed_error.rb +24 -9
  75. data/lib/new_relic/rack.rb +4 -0
  76. data/lib/new_relic/rack/browser_monitoring.rb +28 -10
  77. data/lib/new_relic/rack/developer_mode.rb +3 -0
  78. data/lib/new_relic/rack/error_collector.rb +56 -0
  79. data/lib/new_relic/transaction_sample.rb +23 -13
  80. data/lib/new_relic/transaction_sample/segment.rb +13 -15
  81. data/lib/new_relic/version.rb +3 -3
  82. data/lib/tasks/tests.rake +8 -8
  83. data/newrelic.yml +15 -32
  84. data/newrelic_rpm.gemspec +158 -38
  85. data/newrelic_rpm.gemspec.erb +55 -0
  86. data/test/config/newrelic.yml +3 -2
  87. data/test/intentional_fail.rb +10 -0
  88. data/test/multiverse/.gitignore +10 -0
  89. data/test/multiverse/README.md +90 -0
  90. data/test/multiverse/Rakefile +17 -0
  91. data/test/multiverse/lib/multiverse/color.rb +13 -0
  92. data/test/multiverse/lib/multiverse/envfile.rb +66 -0
  93. data/test/multiverse/lib/multiverse/environment.rb +16 -0
  94. data/test/multiverse/lib/multiverse/output_collector.rb +29 -0
  95. data/test/multiverse/lib/multiverse/runner.rb +44 -0
  96. data/test/multiverse/lib/multiverse/suite.rb +162 -0
  97. data/test/multiverse/script/run_one +3 -0
  98. data/test/multiverse/script/runner +9 -0
  99. data/test/multiverse/suites/active_record/Envfile +13 -0
  100. data/test/multiverse/suites/active_record/ar_method_aliasing.rb +94 -0
  101. data/test/multiverse/suites/active_record/config/newrelic.yml +22 -0
  102. data/test/multiverse/suites/active_record/encoding_test.rb +26 -0
  103. data/test/multiverse/suites/agent_only/Envfile +3 -0
  104. data/test/multiverse/suites/agent_only/config/newrelic.yml +22 -0
  105. data/test/multiverse/suites/agent_only/http_response_code_test.rb +53 -0
  106. data/test/multiverse/suites/agent_only/marshaling_test.rb +109 -0
  107. data/test/multiverse/suites/agent_only/method_visibility_test.rb +98 -0
  108. data/test/multiverse/suites/agent_only/pipe_manager_test.rb +33 -0
  109. data/test/multiverse/suites/agent_only/service_timeout_test.rb +29 -0
  110. data/test/multiverse/suites/agent_only/test_trace_method_with_punctuation.rb +30 -0
  111. data/test/multiverse/suites/agent_only/test_trace_transaction_with_punctuation.rb +32 -0
  112. data/test/multiverse/suites/agent_only/thread_profiling_test.rb +80 -0
  113. data/test/multiverse/suites/datamapper/Envfile +8 -0
  114. data/test/multiverse/suites/datamapper/config/newrelic.yml +22 -0
  115. data/test/multiverse/suites/datamapper/encoding_test.rb +36 -0
  116. data/test/multiverse/suites/monitor_mode_false/Envfile +2 -0
  117. data/test/multiverse/suites/monitor_mode_false/config/newrelic.yml +25 -0
  118. data/test/multiverse/suites/monitor_mode_false/no_dns_resolv.rb +29 -0
  119. data/test/multiverse/suites/no_load/Envfile +2 -0
  120. data/test/multiverse/suites/no_load/config/newrelic.yml +23 -0
  121. data/test/multiverse/suites/no_load/start_up_test.rb +14 -0
  122. data/test/multiverse/suites/rails_3_error_tracing/Envfile +15 -0
  123. data/test/multiverse/suites/rails_3_error_tracing/config/newrelic.yml +165 -0
  124. data/test/multiverse/suites/rails_3_error_tracing/error_tracing_test.rb +236 -0
  125. data/test/multiverse/suites/rails_3_gc/Envfile +8 -0
  126. data/test/multiverse/suites/rails_3_gc/config/newrelic.yml +167 -0
  127. data/test/multiverse/suites/rails_3_gc/instrumentation_test.rb +92 -0
  128. data/test/multiverse/suites/rails_3_queue_time/Envfile +15 -0
  129. data/test/multiverse/suites/rails_3_queue_time/config/newrelic.yml +165 -0
  130. data/test/multiverse/suites/rails_3_queue_time/queue_time_test.rb +75 -0
  131. data/test/multiverse/suites/rails_3_views/.gitignore +3 -0
  132. data/test/multiverse/suites/rails_3_views/Envfile +16 -0
  133. data/test/multiverse/suites/rails_3_views/app/views/foos/_foo.html.haml +1 -0
  134. data/test/multiverse/suites/rails_3_views/app/views/test/_a_partial.html.erb +1 -0
  135. data/test/multiverse/suites/rails_3_views/app/views/test/_mid_partial.html.erb +1 -0
  136. data/test/multiverse/suites/rails_3_views/app/views/test/_top_partial.html.erb +3 -0
  137. data/test/multiverse/suites/rails_3_views/app/views/test/deep_partial.html.erb +3 -0
  138. data/test/multiverse/suites/rails_3_views/app/views/test/haml_view.html.haml +6 -0
  139. data/test/multiverse/suites/rails_3_views/app/views/test/index.html.erb +4 -0
  140. data/test/multiverse/suites/rails_3_views/config/newrelic.yml +164 -0
  141. data/test/multiverse/suites/rails_3_views/view_instrumentation_test.rb +245 -0
  142. data/test/multiverse/suites/resque/Envfile +21 -0
  143. data/test/multiverse/suites/resque/config/newrelic.yml +22 -0
  144. data/test/multiverse/suites/resque/dump.rdb +0 -0
  145. data/test/multiverse/suites/resque/instrumentation_test.rb +73 -0
  146. data/test/multiverse/suites/rum_auto_instrumentation/Envfile +4 -0
  147. data/test/multiverse/suites/rum_auto_instrumentation/config/newrelic.yml +24 -0
  148. data/test/multiverse/suites/rum_auto_instrumentation/problem_response.html +422 -0
  149. data/test/multiverse/suites/rum_auto_instrumentation/responses/worst_case_small.html +5000 -0
  150. data/test/multiverse/suites/rum_auto_instrumentation/sanity_test.rb +115 -0
  151. data/test/multiverse/suites/sinatra/Envfile +13 -0
  152. data/test/multiverse/suites/sinatra/config/newrelic.yml +24 -0
  153. data/test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb +76 -0
  154. data/test/multiverse/suites/sinatra/sinatra_routes_test.rb +46 -0
  155. data/test/multiverse/test/multiverse_test.rb +55 -0
  156. data/test/multiverse/test/suite_examples/one/a/Envfile +3 -0
  157. data/test/multiverse/test/suite_examples/one/a/a_test.rb +11 -0
  158. data/test/multiverse/test/suite_examples/one/a/config/newrelic.yml +24 -0
  159. data/test/multiverse/test/suite_examples/one/b/Envfile +3 -0
  160. data/test/multiverse/test/suite_examples/one/b/b_test.rb +11 -0
  161. data/test/multiverse/test/suite_examples/one/b/config/newrelic.yml +24 -0
  162. data/test/multiverse/test/suite_examples/three/a/Envfile +2 -0
  163. data/test/multiverse/test/suite_examples/three/a/fail_test.rb +6 -0
  164. data/test/multiverse/test/suite_examples/three/b/Envfile +2 -0
  165. data/test/multiverse/test/suite_examples/three/b/win_test.rb +6 -0
  166. data/test/multiverse/test/suite_examples/two/a/Envfile +1 -0
  167. data/test/multiverse/test/suite_examples/two/a/fail_test.rb +6 -0
  168. data/test/new_relic/agent/agent/connect_test.rb +134 -164
  169. data/test/new_relic/agent/agent/start_test.rb +111 -81
  170. data/test/new_relic/agent/agent/start_worker_thread_test.rb +6 -33
  171. data/test/new_relic/agent/agent_test.rb +88 -9
  172. data/test/new_relic/agent/agent_test_controller.rb +1 -1
  173. data/test/new_relic/agent/agent_test_controller_test.rb +42 -10
  174. data/test/new_relic/agent/beacon_configuration_test.rb +63 -67
  175. data/test/new_relic/agent/browser_monitoring_test.rb +150 -79
  176. data/test/new_relic/agent/configuration/environment_source_test.rb +74 -0
  177. data/test/new_relic/agent/configuration/manager_test.rb +149 -0
  178. data/test/new_relic/agent/configuration/server_source_test.rb +45 -0
  179. data/test/new_relic/agent/configuration/yaml_source_test.rb +56 -0
  180. data/test/new_relic/agent/error_collector/notice_error_test.rb +63 -50
  181. data/test/new_relic/agent/error_collector_test.rb +22 -12
  182. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +21 -11
  183. data/test/new_relic/agent/instrumentation/metric_frame_test.rb +6 -0
  184. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +2 -2
  185. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +5 -5
  186. data/test/new_relic/agent/method_tracer_test.rb +6 -6
  187. data/test/new_relic/agent/mock_scope_listener.rb +3 -0
  188. data/test/new_relic/agent/new_relic_service_test.rb +208 -23
  189. data/test/new_relic/agent/pipe_channel_manager_test.rb +34 -17
  190. data/test/new_relic/agent/rpm_agent_test.rb +27 -23
  191. data/test/new_relic/agent/sql_sampler_test.rb +81 -56
  192. data/test/new_relic/agent/stats_engine/metric_stats/harvest_test.rb +3 -20
  193. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +12 -1
  194. data/test/new_relic/agent/stats_engine_test.rb +17 -8
  195. data/test/new_relic/agent/thread_profiler_test.rb +536 -0
  196. data/test/new_relic/agent/thread_test.rb +76 -0
  197. data/test/new_relic/agent/threaded_test.rb +65 -0
  198. data/test/new_relic/agent/transaction_info_test.rb +45 -4
  199. data/test/new_relic/agent/transaction_sample_builder_test.rb +8 -6
  200. data/test/new_relic/agent/transaction_sampler_test.rb +193 -204
  201. data/test/new_relic/agent/worker_loop_test.rb +20 -0
  202. data/test/new_relic/agent_test.rb +69 -41
  203. data/test/new_relic/collection_helper_test.rb +7 -8
  204. data/test/new_relic/command/deployments_test.rb +18 -2
  205. data/test/new_relic/control/frameworks/rails_test.rb +26 -0
  206. data/test/new_relic/control/logging_methods_test.rb +78 -52
  207. data/test/new_relic/control_test.rb +91 -129
  208. data/test/new_relic/fake_collector.rb +103 -31
  209. data/test/new_relic/fake_service.rb +8 -2
  210. data/test/new_relic/load_test.rb +13 -0
  211. data/test/new_relic/local_environment_test.rb +7 -10
  212. data/test/new_relic/metric_data_test.rb +45 -16
  213. data/test/new_relic/noticed_error_test.rb +14 -0
  214. data/test/new_relic/rack/browser_monitoring_test.rb +15 -9
  215. data/test/new_relic/rack/developer_mode_test.rb +13 -7
  216. data/test/new_relic/rack/error_collector_test.rb +74 -0
  217. data/test/new_relic/transaction_sample/segment_test.rb +23 -4
  218. data/test/new_relic/transaction_sample_test.rb +47 -2
  219. data/test/script/build_test_gem.sh +9 -3
  220. data/test/script/ci.sh +48 -21
  221. data/test/script/ci_multiverse_runner.sh +11 -11
  222. data/test/test_helper.rb +37 -18
  223. data/ui/helpers/developer_mode_helper.rb +21 -11
  224. data/ui/views/layouts/newrelic_default.rhtml +1 -0
  225. data/ui/views/newrelic/show_sample.rhtml +1 -1
  226. data/ui/views/newrelic/threads.rhtml +2 -10
  227. data/vendor/gems/metric_parser-0.1.0.pre1/.specification +116 -0
  228. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_init.rb +7 -0
  229. metadata +132 -58
  230. data/lib/new_relic/control/configuration.rb +0 -206
  231. data/test/new_relic/control/configuration_test.rb +0 -77
@@ -33,7 +33,7 @@ module NewRelic
33
33
  # Return nil if there is no backtrace
34
34
 
35
35
  def strip_nr_from_backtrace(backtrace)
36
- if backtrace && !NewRelic::Control.instance.disable_backtrace_cleanup?
36
+ if backtrace && !Agent.config[:disable_backtrace_cleanup]
37
37
  # this is for 1.9.1, where strings no longer have Enumerable
38
38
  backtrace = backtrace.split("\n") if String === backtrace
39
39
  backtrace = backtrace.map &:to_s
@@ -11,7 +11,7 @@ require 'rexml/document'
11
11
  require 'new_relic/control' unless defined? NewRelic::Control
12
12
 
13
13
  class NewRelic::Command::Deployments < NewRelic::Command
14
- attr_reader :config
14
+ attr_reader :control
15
15
  def self.command; "deployments"; end
16
16
 
17
17
  # Initialize the deployment uploader with command line args.
@@ -24,12 +24,18 @@ class NewRelic::Command::Deployments < NewRelic::Command
24
24
  # Will throw CommandFailed exception if there's any error.
25
25
  #
26
26
  def initialize command_line_args
27
- @config = NewRelic::Control.instance
27
+ @control = NewRelic::Control.instance
28
28
  super(command_line_args)
29
29
  @description ||= @leftover && @leftover.join(" ")
30
30
  @user ||= ENV['USER']
31
- config.env = @environment if @environment
32
- @appname ||= config.app_names[0] || config.env || 'development'
31
+ control.env = @environment if @environment
32
+ load_yaml_from_env(control.env)
33
+ @appname ||= NewRelic::Agent.config.app_names[0] || control.env || 'development'
34
+ end
35
+
36
+ def load_yaml_from_env(env)
37
+ yaml = NewRelic::Agent::Configuration::YamlSource.new(NewRelic::Agent.config[:config_path], env)
38
+ NewRelic::Agent.config.replace_or_add_config(yaml, 1)
33
39
  end
34
40
 
35
41
  # Run the Deployment upload in New Relic via Active Resource.
@@ -48,12 +54,15 @@ class NewRelic::Command::Deployments < NewRelic::Command
48
54
  }.each do |k, v|
49
55
  create_params["deployment[#{k}]"] = v unless v.nil? || v == ''
50
56
  end
51
- http = config.http_connection(config.api_server)
57
+ http = control.http_connection(control.api_server)
52
58
 
53
59
  uri = "/deployments.xml"
54
60
 
55
- raise "license_key was not set in newrelic.yml for #{config.env}" if config['license_key'].nil?
56
- request = Net::HTTP::Post.new(uri, {'x-license-key' => config['license_key']})
61
+ if NewRelic::Agent.config[:license_key].nil? ||
62
+ NewRelic::Agent.config[:license_key].empty?
63
+ raise "license_key was not set in newrelic.yml for #{control.env}"
64
+ end
65
+ request = Net::HTTP::Post.new(uri, {'x-license-key' => NewRelic::Agent.config[:license_key]})
57
66
  request.content_type = "application/octet-stream"
58
67
 
59
68
  request.set_form_data(create_params)
@@ -68,12 +77,12 @@ class NewRelic::Command::Deployments < NewRelic::Command
68
77
  end
69
78
  rescue SystemCallError, SocketError => e
70
79
  # These include Errno connection errors
71
- err_string = "Transient error attempting to connect to #{config.api_server} (#{e})"
80
+ err_string = "Transient error attempting to connect to #{control.api_server} (#{e})"
72
81
  raise NewRelic::Command::CommandFailure.new(err_string)
73
82
  rescue NewRelic::Command::CommandFailure
74
83
  raise
75
84
  rescue => e
76
- err "Unexpected error attempting to connect to #{config.api_server}"
85
+ err "Unexpected error attempting to connect to #{control.api_server}"
77
86
  info "#{e}: #{e.backtrace.join("\n ")}"
78
87
  raise NewRelic::Command::CommandFailure.new(e.to_s)
79
88
  end
@@ -89,7 +98,7 @@ class NewRelic::Command::Deployments < NewRelic::Command
89
98
  "Default is app_name setting in newrelic.yml") { | e | @appname = e }
90
99
  o.on("-e", "--environment=name", String,
91
100
  "Override the (RAILS|MERB|RUBY|RACK)_ENV setting",
92
- "currently: #{config.env}") { | e | @environment = e }
101
+ "currently: #{control.env}") { | e | @environment = e }
93
102
  o.on("-u", "--user=USER", String,
94
103
  "Specify the user deploying, for information only",
95
104
  "Default: #{@user || '<none>'}") { | u | @user = u }
@@ -12,7 +12,6 @@ require 'logger'
12
12
  require 'new_relic/control/frameworks'
13
13
  require 'new_relic/control/profiling'
14
14
  require 'new_relic/control/logging_methods'
15
- require 'new_relic/control/configuration'
16
15
  require 'new_relic/control/server_methods'
17
16
  require 'new_relic/control/instrumentation'
18
17
  require 'new_relic/control/class_methods'
@@ -8,7 +8,7 @@ module NewRelic
8
8
  def instance(create=true)
9
9
  @instance ||= create && new_instance
10
10
  end
11
-
11
+
12
12
  # Access the LocalEnvironment singleton, lazy initialized
13
13
  def local_env
14
14
  @local_env ||= NewRelic::LocalEnvironment.new
@@ -29,7 +29,7 @@ module NewRelic
29
29
  require "config/test_control"
30
30
  NewRelic::Control::Frameworks::Test.new(local_env, config)
31
31
  end
32
-
32
+
33
33
  # Loads the specified framework class from the
34
34
  # NewRelic::Control::Frameworks module
35
35
  def load_framework_class(framework)
@@ -50,4 +50,3 @@ module NewRelic
50
50
  extend ClassMethods
51
51
  end
52
52
  end
53
-
@@ -21,30 +21,35 @@ module NewRelic
21
21
  ::RAILS_DEFAULT_LOGGER
22
22
  end
23
23
 
24
+ def rails_config
25
+ if defined?(::Rails) && ::Rails.respond_to?(:configuration)
26
+ ::Rails.configuration
27
+ else
28
+ @config
29
+ end
30
+ end
31
+
24
32
  # In versions of Rails prior to 2.0, the rails config was only available to
25
- # the init.rb, so it had to be passed on from there. This is a best effort to
33
+ # the init.rb, so it had to be passed on from there. This is a best effort to
26
34
  # find a config and use that.
27
35
  def init_config(options={})
28
- rails_config = options[:config]
29
- if !rails_config && defined?(::Rails) && ::Rails.respond_to?(:configuration)
30
- rails_config = ::Rails.configuration
31
- end
32
- # Install the dependency detection,
36
+ @config = options[:config]
37
+ # Install the dependency detection,
33
38
  if rails_config && ::Rails.configuration.respond_to?(:after_initialize)
34
39
  rails_config.after_initialize do
35
40
  # This will insure we load all the instrumentation as late as possible. If the agent
36
- # is not enabled, it will load a limited amount of instrumentation. See
41
+ # is not enabled, it will load a limited amount of instrumentation. See
37
42
  # delayed_job_injection.rb
38
43
  DependencyDetection.detect!
39
44
  end
40
- end
41
- if !agent_enabled?
45
+ end
46
+ if !Agent.config[:agent_enabled]
42
47
  # Might not be running if it does not think mongrel, thin, passenger, etc
43
- # is running, if it things it's a rake task, or if the agent_enabled is false.
44
- log! "New Relic Agent not running."
48
+ # is running, if it thinks it's a rake task, or if the agent_enabled is false.
49
+ log!("New Relic Agent not running.", :debug)
45
50
  else
46
51
  log! "Starting the New Relic Agent."
47
- install_developer_mode rails_config if developer_mode?
52
+ install_developer_mode rails_config if Agent.config[:developer_mode]
48
53
  install_browser_monitoring(rails_config)
49
54
  end
50
55
  end
@@ -52,7 +57,7 @@ module NewRelic
52
57
  def install_browser_monitoring(config)
53
58
  return if @browser_monitoring_installed
54
59
  @browser_monitoring_installed = true
55
- return if config.nil? || !config.respond_to?(:middleware) || ! browser_monitoring_auto_instrument?
60
+ return if config.nil? || !config.respond_to?(:middleware) || !Agent.config[:'browser_monitoring.auto_instrument']
56
61
  begin
57
62
  require 'new_relic/rack/browser_monitoring'
58
63
  config.middleware.use NewRelic::Rack::BrowserMonitoring
@@ -114,7 +119,7 @@ module NewRelic
114
119
  end
115
120
 
116
121
  def rails_gem_list
117
- ::Rails.configuration.gems.map do | gem |
122
+ ::Rails.configuration.gems.map do |gem|
118
123
  version = (gem.respond_to?(:version) && gem.version) ||
119
124
  (gem.specification.respond_to?(:version) && gem.specification.version)
120
125
  gem.name + (version ? "(#{version})" : "")
@@ -153,11 +158,12 @@ module NewRelic
153
158
  def install_shim
154
159
  super
155
160
  require 'new_relic/agent/instrumentation/controller_instrumentation'
156
- ::ActionController::Base.class_eval {
157
- include NewRelic::Agent::Instrumentation::ControllerInstrumentation::Shim
158
- }
161
+ if ActiveSupport.respond_to?(:on_load) # rails 3+
162
+ ActiveSupport.on_load(:action_controller) { include NewRelic::Agent::Instrumentation::ControllerInstrumentation::Shim }
163
+ else
164
+ ActionController::Base.class_eval { include NewRelic::Agent::Instrumentation::ControllerInstrumentation::Shim }
165
+ end
159
166
  end
160
-
161
167
  end
162
168
  end
163
169
  end
@@ -1,4 +1,5 @@
1
1
  require 'new_relic/control/frameworks/rails'
2
+ require 'new_relic/rack/error_collector'
2
3
  module NewRelic
3
4
  class Control
4
5
  module Frameworks
@@ -30,6 +31,15 @@ module NewRelic
30
31
  ::Rails.logger
31
32
  end
32
33
 
34
+ def init_config(options={})
35
+ super
36
+ if Agent.config[:agent_enabled] && Agent.config[:'error_collector.enabled']
37
+ if !rails_config.middleware.respond_to?(:include?) ||
38
+ !rails_config.middleware.include?(NewRelic::Rack::ErrorCollector)
39
+ rails_config.middleware.use NewRelic::Rack::ErrorCollector
40
+ end
41
+ end
42
+ end
33
43
 
34
44
  def log!(msg, level=:info)
35
45
  if should_log?
@@ -59,7 +69,7 @@ module NewRelic
59
69
 
60
70
  # Collect the Rails::Info into an associative array as well as the list of plugins
61
71
  def append_environment_info
62
- local_env.append_environment_value('Rails version'){ version }
72
+ local_env.append_environment_value('Rails version'){ ::Rails::VERSION::STRING }
63
73
  local_env.append_environment_value('Rails threadsafe') do
64
74
  true == ::Rails.configuration.action_controller.allow_concurrency
65
75
  end
@@ -69,6 +79,13 @@ module NewRelic
69
79
  end
70
80
  local_env.append_plugin_list { ::Rails.configuration.plugins.to_a }
71
81
  end
82
+
83
+ def install_shim
84
+ super
85
+ ActiveSupport.on_load(:action_controller) do
86
+ include NewRelic::Agent::Instrumentation::ControllerInstrumentation::Shim
87
+ end
88
+ end
72
89
  end
73
90
  end
74
91
  end
@@ -12,7 +12,7 @@ module NewRelic
12
12
  @env ||= ENV['RUBY_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
13
13
  end
14
14
  def root
15
- @root ||= ENV['APP_ROOT'] || Dir['.']
15
+ @root ||= ENV['APP_ROOT'] || '.'
16
16
  end
17
17
  # Check a sequence of file locations for newrelic.yml
18
18
  def config_file
@@ -24,7 +24,7 @@ module NewRelic
24
24
  files << File.join(ENV["HOME"], "newrelic.yml")
25
25
  end
26
26
  files << File.expand_path(ENV["NRCONFIG"]) if ENV["NRCONFIG"]
27
- files.each do | file |
27
+ files.each do |file|
28
28
  return File.expand_path(file) if File.exists? file
29
29
  end
30
30
  return File.expand_path(files.first)
@@ -44,6 +44,18 @@ module NewRelic
44
44
  # init_config({}) which is called one or more times.
45
45
  #
46
46
  def init_plugin(options={})
47
+ begin
48
+ path = @newrelic_file || Agent.config[:config_path]
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
57
+
58
+ Agent.config.replace_or_add_config(Agent::Configuration::ManualSource.new(options), 1)
47
59
  options['app_name'] = ENV['NEWRELIC_APP_NAME'] if ENV['NEWRELIC_APP_NAME']
48
60
  options['app_name'] ||= ENV['NEW_RELIC_APP_NAME'] if ENV['NEW_RELIC_APP_NAME']
49
61
 
@@ -52,15 +64,9 @@ module NewRelic
52
64
  environment_name = options.delete(:env) and self.env = environment_name
53
65
  dispatcher = options.delete(:dispatcher) and @local_env.dispatcher = dispatcher
54
66
  dispatcher_instance_id = options.delete(:dispatcher_instance_id) and @local_env.dispatcher_instance_id = dispatcher_instance_id
55
-
67
+
56
68
  NewRelic::Agent::PipeChannelManager.listener.start if options.delete(:start_channel_listener)
57
69
 
58
- # Clear out the settings, if they've already been loaded. It may be that
59
- # between calling init_plugin the first time and the second time, the env
60
- # has been overridden
61
- @settings = nil
62
- settings
63
- merge_options(options)
64
70
  if logger_override
65
71
  @log = logger_override
66
72
  # Try to grab the log filename
@@ -72,14 +78,14 @@ module NewRelic
72
78
  Module.send :include, NewRelic::Agent::MethodTracer::InstanceMethods
73
79
  init_config(options)
74
80
  NewRelic::Agent.agent = NewRelic::Agent::Agent.instance
75
- if agent_enabled? && !NewRelic::Agent.instance.started?
81
+ if Agent.config[:agent_enabled] && !NewRelic::Agent.instance.started?
76
82
  setup_log unless logger_override
77
83
  start_agent
78
84
  install_instrumentation
79
- load_samplers unless self['disable_samplers']
85
+ load_samplers unless Agent.config['disable_samplers']
80
86
  local_env.gather_environment_info
81
87
  append_environment_info
82
- elsif !agent_enabled?
88
+ elsif !Agent.config[:agent_enabled]
83
89
  install_shim
84
90
  end
85
91
  end
@@ -89,42 +95,40 @@ module NewRelic
89
95
  NewRelic::Agent.agent.start
90
96
  end
91
97
 
92
- # True if dev mode or monitor mode are enabled, and we are running
93
- # inside a valid dispatcher like mongrel or passenger. Can be overridden
94
- # by NEWRELIC_ENABLE env variable, monitor_daemons config option when true, or
95
- # agent_enabled config option when true or false.
96
- def agent_enabled?
97
- return false if !developer_mode? && !monitor_mode?
98
- return self['agent_enabled'].to_s =~ /true|on|yes/i if !self['agent_enabled'].nil? && self['agent_enabled'] != 'auto'
99
- return false if ENV['NEWRELIC_ENABLE'].to_s =~ /false|off|no/i
100
- return true if self['monitor_daemons'].to_s =~ /true|on|yes/i
101
- return true if ENV['NEWRELIC_ENABLE'].to_s =~ /true|on|yes/i
102
- # When in 'auto' mode the agent is enabled if there is a known
103
- # dispatcher running
104
- return true if @local_env.dispatcher != nil
105
- end
106
-
107
98
  # Asks the LocalEnvironment instance which framework should be loaded
108
99
  def app
109
100
  @local_env.framework
110
101
  end
111
102
  alias framework app
112
-
103
+
113
104
  def to_s #:nodoc:
114
105
  "Control[#{self.app}]"
115
106
  end
116
107
 
108
+ # for backward compatibility with the old config interface
109
+ def [](key)
110
+ NewRelic::Agent.config[key.to_sym]
111
+ end
112
+
113
+ def settings
114
+ NewRelic::Agent.config.flattened_config
115
+ end
116
+
117
+ def dispatcher
118
+ NewRelic::Agent.config[:dispatcher]
119
+ end
120
+
117
121
  protected
118
122
 
119
123
  # Append framework specific environment information for uploading to
120
124
  # the server for change detection. Override in subclasses
121
125
  def append_environment_info; end
122
-
126
+
123
127
  # Asks bundler to tell us which gemspecs are loaded in the
124
128
  # current process
125
129
  def bundler_gem_list
126
130
  if defined?(Bundler) && Bundler.instance_eval do @load end
127
- Bundler.load.specs.map do | spec |
131
+ Bundler.load.specs.map do |spec|
128
132
  version = (spec.respond_to?(:version) && spec.version)
129
133
  spec.name + (version ? "(#{version})" : "")
130
134
  end
@@ -132,39 +136,18 @@ module NewRelic
132
136
  []
133
137
  end
134
138
  end
135
-
139
+
136
140
  # path to the config file, defaults to the "#{root}/config/newrelic.yml"
137
141
  def config_file
138
142
  File.expand_path(File.join(root,"config","newrelic.yml"))
139
143
  end
140
-
141
- # initializes the control instance with a local environment and
142
- # an optional config file override. Checks for the config file
143
- # and loads it.
144
+
144
145
  def initialize local_env, config_file_override=nil
145
146
  @local_env = local_env
146
147
  @instrumentation_files = []
147
- newrelic_file = config_file_override || config_file
148
- # Next two are for populating the newrelic.yml via erb binding, necessary
149
- # when using the default newrelic.yml file
150
- generated_for_user = ''
151
- license_key=''
152
- if !File.exists?(newrelic_file)
153
- puts "Cannot find or read #{newrelic_file}"
154
- @yaml = {}
155
- else
156
- @yaml = load_newrelic_yml(newrelic_file, binding)
157
- end
158
- rescue ScriptError, StandardError => e
159
- new_err = e.class.new("Error reading newrelic.yml file: #{e}")
160
- new_err.set_backtrace(e.backtrace)
161
- raise new_err
148
+ @newrelic_file = config_file_override || config_file
162
149
  end
163
-
164
- def load_newrelic_yml(path, binding)
165
- YAML.load(ERB.new(File.read(path)).result(binding))
166
- end
167
-
150
+
168
151
  def root
169
152
  '.'
170
153
  end
@@ -32,7 +32,7 @@ module NewRelic
32
32
  # true if the agent has settings, and the agent is enabled,
33
33
  # otherwise false
34
34
  def should_log?
35
- @settings && agent_enabled?
35
+ @settings && Agent.config[:agent_enabled]
36
36
  end
37
37
 
38
38
  # set the log level as specified in the config file
@@ -41,7 +41,7 @@ module NewRelic
41
41
  #error, and fatal
42
42
  # Defaults to info
43
43
  def set_log_level!(logger)
44
- case fetch("log_level","info").downcase
44
+ case Agent.config[:log_level].downcase
45
45
  when "debug" then logger.level = Logger::DEBUG
46
46
  when "info" then logger.level = Logger::INFO
47
47
  when "warn" then logger.level = Logger::WARN
@@ -68,7 +68,7 @@ module NewRelic
68
68
  if log_to_stdout?
69
69
  @log = Logger.new(STDOUT)
70
70
  else
71
- @log_file = "#{log_path}/#{log_file_name}"
71
+ @log_file = "#{log_path}/#{Agent.config[:log_file_name]}"
72
72
  @log = Logger.new(@log_file) rescue nil
73
73
  @log ||= Logger.new(STDOUT) # failsafe to STDOUT
74
74
  end
@@ -99,11 +99,7 @@ module NewRelic
99
99
  if log_to_stdout?
100
100
  @log_path = nil
101
101
  else
102
- if ENV['NEW_RELIC_LOG']
103
- log_path_setting = File.dirname(ENV['NEW_RELIC_LOG'])
104
- else
105
- log_path_setting = fetch('log_file_path', 'log')
106
- end
102
+ log_path_setting = Agent.config[:log_file_path]
107
103
  @log_path = find_or_create_file_path(log_path_setting)
108
104
  log!("Error creating log directory #{log_path_setting}, using standard out for logging.", :warn) unless @log_path
109
105
  end
@@ -121,21 +117,7 @@ module NewRelic
121
117
  end
122
118
 
123
119
  def log_to_stdout?
124
- return true if @stdout
125
- destination = ENV['NEW_RELIC_LOG'] || fetch('log_file_path', 'log')
126
- if destination.upcase == 'STDOUT'
127
- @stdout = true
128
- end
129
- end
130
-
131
- # Retrieves the log file's name from the config file option
132
- #'log_file_name', defaulting to 'newrelic_agent.log'
133
- def log_file_name
134
- if ENV['NEW_RELIC_LOG']
135
- File.basename(ENV['NEW_RELIC_LOG'])
136
- else
137
- fetch('log_file_name', 'newrelic_agent.log')
138
- end
120
+ Agent.config['log_file_path'].upcase == 'STDOUT'
139
121
  end
140
122
  end
141
123
  include LoggingMethods