wd_newrelic_rpm 3.3.4.1 → 3.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (290) hide show
  1. data/.gitignore +20 -0
  2. data/.project +23 -0
  3. data/.travis.yml +9 -0
  4. data/CHANGELOG +317 -39
  5. data/GUIDELINES_FOR_CONTRIBUTING.md +76 -0
  6. data/Gemfile +16 -0
  7. data/LICENSE +1 -1
  8. data/{README.rdoc → README.md} +71 -55
  9. data/Rakefile +62 -0
  10. data/bin/mongrel_rpm +1 -1
  11. data/config.dot +290 -0
  12. data/config/database.yml +5 -0
  13. data/init.rb +31 -0
  14. data/lib/new_relic/agent.rb +31 -60
  15. data/lib/new_relic/agent/agent.rb +277 -502
  16. data/lib/new_relic/agent/agent_logger.rb +165 -0
  17. data/lib/new_relic/agent/audit_logger.rb +72 -0
  18. data/lib/new_relic/agent/beacon_configuration.rb +36 -50
  19. data/lib/new_relic/agent/browser_monitoring.rb +114 -61
  20. data/lib/new_relic/agent/busy_calculator.rb +14 -6
  21. data/lib/new_relic/agent/configuration.rb +74 -0
  22. data/lib/new_relic/agent/configuration/defaults.rb +126 -0
  23. data/lib/new_relic/agent/configuration/environment_source.rb +49 -0
  24. data/lib/new_relic/agent/configuration/manager.rb +136 -0
  25. data/lib/new_relic/agent/configuration/mask_defaults.rb +10 -0
  26. data/lib/new_relic/agent/configuration/server_source.rb +27 -0
  27. data/lib/new_relic/agent/configuration/yaml_source.rb +63 -0
  28. data/lib/new_relic/agent/cross_process_monitoring.rb +43 -0
  29. data/lib/new_relic/agent/database.rb +39 -26
  30. data/lib/new_relic/agent/error_collector.rb +48 -49
  31. data/lib/new_relic/agent/instrumentation/active_merchant.rb +1 -1
  32. data/lib/new_relic/agent/instrumentation/active_record.rb +4 -7
  33. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +1 -1
  34. data/lib/new_relic/agent/instrumentation/authlogic.rb +1 -1
  35. data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +41 -0
  36. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +35 -12
  37. data/lib/new_relic/agent/instrumentation/data_mapper.rb +4 -12
  38. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +2 -2
  39. data/lib/new_relic/agent/instrumentation/memcache.rb +6 -6
  40. data/lib/new_relic/agent/instrumentation/merb/controller.rb +1 -1
  41. data/lib/new_relic/agent/instrumentation/merb/errors.rb +1 -1
  42. data/lib/new_relic/agent/instrumentation/metric_frame.rb +4 -14
  43. data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +1 -1
  44. data/lib/new_relic/agent/instrumentation/net.rb +1 -1
  45. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +6 -20
  46. data/lib/new_relic/agent/instrumentation/queue_time.rb +2 -2
  47. data/lib/new_relic/agent/instrumentation/rack.rb +1 -1
  48. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +7 -7
  49. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +1 -1
  50. data/lib/new_relic/agent/instrumentation/rails/errors.rb +1 -1
  51. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +5 -5
  52. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +6 -2
  53. data/lib/new_relic/agent/instrumentation/resque.rb +81 -0
  54. data/lib/new_relic/agent/instrumentation/sinatra.rb +21 -10
  55. data/lib/new_relic/agent/instrumentation/sunspot.rb +1 -1
  56. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +5 -4
  57. data/lib/new_relic/agent/method_tracer.rb +11 -9
  58. data/lib/new_relic/agent/new_relic_service.rb +379 -0
  59. data/lib/new_relic/agent/pipe_channel_manager.rb +175 -0
  60. data/lib/new_relic/agent/pipe_service.rb +58 -0
  61. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +86 -0
  62. data/lib/new_relic/agent/samplers/memory_sampler.rb +6 -8
  63. data/lib/new_relic/agent/sql_sampler.rb +31 -74
  64. data/lib/new_relic/agent/stats_engine.rb +0 -5
  65. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +40 -24
  66. data/lib/new_relic/agent/stats_engine/metric_stats.rb +89 -14
  67. data/lib/new_relic/agent/stats_engine/samplers.rb +9 -7
  68. data/lib/new_relic/agent/stats_engine/transactions.rb +20 -12
  69. data/lib/new_relic/agent/thread.rb +32 -0
  70. data/lib/new_relic/agent/thread_profiler.rb +306 -0
  71. data/lib/new_relic/agent/transaction_info.rb +24 -4
  72. data/lib/new_relic/agent/transaction_sample_builder.rb +12 -13
  73. data/lib/new_relic/agent/transaction_sampler.rb +49 -65
  74. data/lib/new_relic/agent/worker_loop.rb +31 -25
  75. data/lib/new_relic/collection_helper.rb +1 -1
  76. data/lib/new_relic/commands/deployments.rb +19 -10
  77. data/lib/new_relic/control.rb +1 -3
  78. data/lib/new_relic/control/class_methods.rb +10 -5
  79. data/lib/new_relic/control/frameworks/merb.rb +0 -6
  80. data/lib/new_relic/control/frameworks/rails.rb +30 -45
  81. data/lib/new_relic/control/frameworks/rails3.rb +23 -18
  82. data/lib/new_relic/control/frameworks/rails4.rb +23 -0
  83. data/lib/new_relic/control/frameworks/ruby.rb +2 -23
  84. data/lib/new_relic/control/instance_methods.rb +35 -73
  85. data/lib/new_relic/control/instrumentation.rb +7 -12
  86. data/lib/new_relic/control/server_methods.rb +17 -19
  87. data/lib/new_relic/delayed_job_injection.rb +2 -2
  88. data/lib/new_relic/helper.rb +34 -0
  89. data/lib/new_relic/language_support.rb +56 -37
  90. data/lib/new_relic/local_environment.rb +32 -67
  91. data/lib/new_relic/metric_data.rb +10 -2
  92. data/lib/new_relic/metric_spec.rb +7 -3
  93. data/lib/new_relic/noticed_error.rb +32 -9
  94. data/lib/new_relic/rack.rb +4 -0
  95. data/lib/new_relic/rack/browser_monitoring.rb +34 -25
  96. data/lib/new_relic/rack/developer_mode.rb +3 -0
  97. data/lib/new_relic/rack/error_collector.rb +56 -0
  98. data/lib/new_relic/stats.rb +9 -7
  99. data/lib/new_relic/transaction_sample.rb +19 -18
  100. data/lib/new_relic/transaction_sample/segment.rb +13 -15
  101. data/lib/new_relic/version.rb +19 -3
  102. data/lib/newrelic_rpm.rb +1 -1
  103. data/lib/tasks/tests.rake +6 -8
  104. data/newrelic.yml +15 -32
  105. data/newrelic_rpm.gemspec +224 -43
  106. data/newrelic_rpm.gemspec.erb +54 -0
  107. data/test/config/newrelic.yml +4 -3
  108. data/test/config/test_control.rb +18 -18
  109. data/test/fixtures/gemspec_no_build.rb +442 -0
  110. data/test/fixtures/gemspec_with_build.rb +442 -0
  111. data/test/fixtures/gemspec_with_build_and_stage.rb +442 -0
  112. data/test/intentional_fail.rb +10 -0
  113. data/test/multiverse/.gitignore +10 -0
  114. data/test/multiverse/README.md +85 -0
  115. data/test/multiverse/lib/multiverse/color.rb +13 -0
  116. data/test/multiverse/lib/multiverse/envfile.rb +66 -0
  117. data/test/multiverse/lib/multiverse/environment.rb +16 -0
  118. data/test/multiverse/lib/multiverse/output_collector.rb +29 -0
  119. data/test/multiverse/lib/multiverse/runner.rb +44 -0
  120. data/test/multiverse/lib/multiverse/suite.rb +162 -0
  121. data/test/multiverse/script/run_one +3 -0
  122. data/test/multiverse/script/runner +9 -0
  123. data/test/multiverse/suites/active_record/Envfile +13 -0
  124. data/test/multiverse/suites/active_record/ar_method_aliasing.rb +94 -0
  125. data/test/multiverse/suites/active_record/config/newrelic.yml +22 -0
  126. data/test/multiverse/suites/active_record/encoding_test.rb +26 -0
  127. data/test/multiverse/suites/agent_only/Envfile +4 -0
  128. data/test/multiverse/suites/agent_only/audit_log_test.rb +99 -0
  129. data/test/multiverse/suites/agent_only/config/newrelic.yml +22 -0
  130. data/test/multiverse/suites/agent_only/http_response_code_test.rb +53 -0
  131. data/test/multiverse/suites/agent_only/marshaling_test.rb +109 -0
  132. data/test/multiverse/suites/agent_only/method_visibility_test.rb +98 -0
  133. data/test/multiverse/suites/agent_only/pipe_manager_test.rb +33 -0
  134. data/test/multiverse/suites/agent_only/service_timeout_test.rb +29 -0
  135. data/test/multiverse/suites/agent_only/test_trace_method_with_punctuation.rb +30 -0
  136. data/test/multiverse/suites/agent_only/test_trace_transaction_with_punctuation.rb +32 -0
  137. data/test/multiverse/suites/agent_only/thread_profiling_test.rb +80 -0
  138. data/test/multiverse/suites/config_file_loading/Envfile +7 -0
  139. data/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +106 -0
  140. data/test/multiverse/suites/datamapper/Envfile +8 -0
  141. data/test/multiverse/suites/datamapper/config/newrelic.yml +22 -0
  142. data/test/multiverse/suites/datamapper/encoding_test.rb +36 -0
  143. data/test/multiverse/suites/logging/Envfile +4 -0
  144. data/test/multiverse/suites/logging/config/newrelic.yml +22 -0
  145. data/test/multiverse/suites/logging/logging_test.rb +143 -0
  146. data/test/multiverse/suites/monitor_mode_false/Envfile +2 -0
  147. data/test/multiverse/suites/monitor_mode_false/config/newrelic.yml +25 -0
  148. data/test/multiverse/suites/monitor_mode_false/no_dns_resolv.rb +29 -0
  149. data/test/multiverse/suites/no_load/Envfile +2 -0
  150. data/test/multiverse/suites/no_load/config/newrelic.yml +22 -0
  151. data/test/multiverse/suites/no_load/start_up_test.rb +14 -0
  152. data/test/multiverse/suites/rails_3_error_tracing/Envfile +15 -0
  153. data/test/multiverse/suites/rails_3_error_tracing/config/newrelic.yml +165 -0
  154. data/test/multiverse/suites/rails_3_error_tracing/error_tracing_test.rb +236 -0
  155. data/test/multiverse/suites/rails_3_gc/Envfile +8 -0
  156. data/test/multiverse/suites/rails_3_gc/config/newrelic.yml +167 -0
  157. data/test/multiverse/suites/rails_3_gc/instrumentation_test.rb +92 -0
  158. data/test/multiverse/suites/rails_3_queue_time/Envfile +15 -0
  159. data/test/multiverse/suites/rails_3_queue_time/config/newrelic.yml +165 -0
  160. data/test/multiverse/suites/rails_3_queue_time/queue_time_test.rb +75 -0
  161. data/test/multiverse/suites/rails_3_views/.gitignore +3 -0
  162. data/test/multiverse/suites/rails_3_views/Envfile +16 -0
  163. data/test/multiverse/suites/rails_3_views/app/views/foos/_foo.html.haml +1 -0
  164. data/test/multiverse/suites/rails_3_views/app/views/test/_a_partial.html.erb +1 -0
  165. data/test/multiverse/suites/rails_3_views/app/views/test/_mid_partial.html.erb +1 -0
  166. data/test/multiverse/suites/rails_3_views/app/views/test/_top_partial.html.erb +3 -0
  167. data/test/multiverse/suites/rails_3_views/app/views/test/deep_partial.html.erb +3 -0
  168. data/test/multiverse/suites/rails_3_views/app/views/test/haml_view.html.haml +6 -0
  169. data/test/multiverse/suites/rails_3_views/app/views/test/index.html.erb +4 -0
  170. data/test/multiverse/suites/rails_3_views/config/newrelic.yml +164 -0
  171. data/test/multiverse/suites/rails_3_views/view_instrumentation_test.rb +245 -0
  172. data/test/multiverse/suites/resque/Envfile +21 -0
  173. data/test/multiverse/suites/resque/config/newrelic.yml +22 -0
  174. data/test/multiverse/suites/resque/dump.rdb +0 -0
  175. data/test/multiverse/suites/resque/instrumentation_test.rb +73 -0
  176. data/test/multiverse/suites/rum_auto_instrumentation/Envfile +4 -0
  177. data/test/multiverse/suites/rum_auto_instrumentation/config/newrelic.yml +24 -0
  178. data/test/multiverse/suites/rum_auto_instrumentation/responses/worst_case_small.html +5000 -0
  179. data/test/multiverse/suites/rum_auto_instrumentation/sanity_test.rb +102 -0
  180. data/test/multiverse/suites/sinatra/Envfile +13 -0
  181. data/test/multiverse/suites/sinatra/config/newrelic.yml +24 -0
  182. data/test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb +77 -0
  183. data/test/multiverse/suites/sinatra/sinatra_routes_test.rb +46 -0
  184. data/test/multiverse/suites/sinatra/sinatra_test.rb +55 -0
  185. data/test/multiverse/test/multiverse_test.rb +55 -0
  186. data/test/multiverse/test/suite_examples/one/a/Envfile +3 -0
  187. data/test/multiverse/test/suite_examples/one/a/a_test.rb +11 -0
  188. data/test/multiverse/test/suite_examples/one/a/config/newrelic.yml +24 -0
  189. data/test/multiverse/test/suite_examples/one/b/Envfile +3 -0
  190. data/test/multiverse/test/suite_examples/one/b/b_test.rb +11 -0
  191. data/test/multiverse/test/suite_examples/one/b/config/newrelic.yml +24 -0
  192. data/test/multiverse/test/suite_examples/three/a/Envfile +2 -0
  193. data/test/multiverse/test/suite_examples/three/a/fail_test.rb +6 -0
  194. data/test/multiverse/test/suite_examples/three/b/Envfile +2 -0
  195. data/test/multiverse/test/suite_examples/three/b/win_test.rb +6 -0
  196. data/test/multiverse/test/suite_examples/two/a/Envfile +1 -0
  197. data/test/multiverse/test/suite_examples/two/a/fail_test.rb +6 -0
  198. data/test/new_relic/agent/agent/connect_test.rb +151 -227
  199. data/test/new_relic/agent/agent/start_test.rb +68 -118
  200. data/test/new_relic/agent/agent/start_worker_thread_test.rb +12 -74
  201. data/test/new_relic/agent/agent_logger_test.rb +153 -0
  202. data/test/new_relic/agent/agent_test.rb +116 -30
  203. data/test/new_relic/agent/agent_test_controller.rb +1 -1
  204. data/test/new_relic/agent/agent_test_controller_test.rb +42 -10
  205. data/test/new_relic/agent/audit_logger_test.rb +105 -0
  206. data/test/new_relic/agent/beacon_configuration_test.rb +63 -67
  207. data/test/new_relic/agent/browser_monitoring_test.rb +151 -79
  208. data/test/new_relic/agent/busy_calculator_test.rb +7 -0
  209. data/test/new_relic/agent/configuration/environment_source_test.rb +79 -0
  210. data/test/new_relic/agent/configuration/manager_test.rb +204 -0
  211. data/test/new_relic/agent/configuration/server_source_test.rb +45 -0
  212. data/test/new_relic/agent/configuration/yaml_source_test.rb +75 -0
  213. data/test/new_relic/agent/cross_process_monitoring_test.rb +77 -0
  214. data/test/new_relic/agent/database_test.rb +12 -11
  215. data/test/new_relic/agent/error_collector/notice_error_test.rb +64 -53
  216. data/test/new_relic/agent/error_collector_test.rb +33 -19
  217. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +60 -30
  218. data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +39 -0
  219. data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +1 -1
  220. data/test/new_relic/agent/instrumentation/metric_frame_test.rb +6 -0
  221. data/test/new_relic/agent/instrumentation/queue_time_test.rb +14 -0
  222. data/test/new_relic/agent/instrumentation/sinatra_test.rb +25 -0
  223. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +2 -2
  224. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +4 -10
  225. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +3 -15
  226. data/test/new_relic/agent/method_tracer_test.rb +7 -6
  227. data/test/new_relic/agent/mock_scope_listener.rb +3 -0
  228. data/test/new_relic/agent/new_relic_service_test.rb +376 -0
  229. data/test/new_relic/agent/pipe_channel_manager_test.rb +131 -0
  230. data/test/new_relic/agent/pipe_service_test.rb +113 -0
  231. data/test/new_relic/agent/rpm_agent_test.rb +27 -50
  232. data/test/new_relic/agent/sql_sampler_test.rb +81 -56
  233. data/test/new_relic/agent/stats_engine/metric_stats/harvest_test.rb +3 -20
  234. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +12 -1
  235. data/test/new_relic/agent/stats_engine_test.rb +17 -8
  236. data/test/new_relic/agent/thread_profiler_test.rb +537 -0
  237. data/test/new_relic/agent/thread_test.rb +89 -0
  238. data/test/new_relic/agent/threaded_test.rb +65 -0
  239. data/test/new_relic/agent/transaction_info_test.rb +45 -4
  240. data/test/new_relic/agent/transaction_sample_builder_test.rb +8 -7
  241. data/test/new_relic/agent/transaction_sampler_test.rb +193 -204
  242. data/test/new_relic/agent/worker_loop_test.rb +26 -11
  243. data/test/new_relic/agent_test.rb +113 -33
  244. data/test/new_relic/collection_helper_test.rb +7 -8
  245. data/test/new_relic/command/deployments_test.rb +18 -2
  246. data/test/new_relic/control/class_methods_test.rb +0 -18
  247. data/test/new_relic/control/frameworks/rails_test.rb +26 -0
  248. data/test/new_relic/control_test.rb +96 -137
  249. data/test/new_relic/delayed_job_injection_test.rb +6 -1
  250. data/test/new_relic/dispatcher_test.rb +54 -0
  251. data/test/new_relic/fake_collector.rb +283 -0
  252. data/test/new_relic/fake_service.rb +53 -0
  253. data/test/new_relic/fakes_sending_data.rb +30 -0
  254. data/test/new_relic/framework_test.rb +53 -0
  255. data/test/new_relic/load_test.rb +13 -0
  256. data/test/new_relic/local_environment_test.rb +11 -11
  257. data/test/new_relic/metric_data_test.rb +45 -16
  258. data/test/new_relic/noticed_error_test.rb +24 -0
  259. data/test/new_relic/rack/browser_monitoring_test.rb +20 -10
  260. data/test/new_relic/rack/developer_mode_test.rb +13 -7
  261. data/test/new_relic/rack/error_collector_test.rb +74 -0
  262. data/test/new_relic/stats_test.rb +10 -0
  263. data/test/new_relic/transaction_sample/segment_test.rb +23 -4
  264. data/test/new_relic/transaction_sample_test.rb +47 -2
  265. data/test/new_relic/version_number_test.rb +32 -0
  266. data/test/script/build_test_gem.sh +9 -3
  267. data/test/script/ci.sh +108 -35
  268. data/test/script/ci_agent-tests_runner.sh +82 -0
  269. data/test/script/ci_multiverse_runner.sh +63 -0
  270. data/test/test_contexts.rb +1 -0
  271. data/test/test_helper.rb +68 -18
  272. data/ui/helpers/developer_mode_helper.rb +21 -11
  273. data/ui/views/layouts/newrelic_default.rhtml +1 -0
  274. data/ui/views/newrelic/file/images/arrow-close.png +0 -0
  275. data/ui/views/newrelic/file/images/arrow-open.png +0 -0
  276. data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
  277. data/ui/views/newrelic/file/images/file_icon.png +0 -0
  278. data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
  279. data/ui/views/newrelic/show_sample.rhtml +1 -1
  280. data/ui/views/newrelic/threads.rhtml +2 -10
  281. data/vendor/gems/metric_parser-0.1.0.pre1/.specification +116 -0
  282. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_init.rb +7 -0
  283. metadata +191 -65
  284. data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +0 -40
  285. data/lib/new_relic/control/configuration.rb +0 -206
  286. data/lib/new_relic/control/logging_methods.rb +0 -143
  287. data/lib/new_relic/data_serialization.rb +0 -151
  288. data/test/new_relic/control/configuration_test.rb +0 -84
  289. data/test/new_relic/control/logging_methods_test.rb +0 -185
  290. data/test/new_relic/data_serialization_test.rb +0 -208
@@ -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
- log.error "Error loading instrumentation file '#{file}': #{e}"
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
- log.debug "#{subclass.name} not supported on this platform." and next if not subclass.supported_on_this_platform?
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
- log.debug "Registered #{subclass.name} for harvest time sampling"
62
+ ::NewRelic::Agent.logger.debug "Registered #{subclass.name} for harvest time sampling"
68
63
  else
69
64
  agent.stats_engine.add_sampler sampler
70
- log.debug "Registered #{subclass.name} for periodic sampling"
65
+ ::NewRelic::Agent.logger.debug "Registered #{subclass.name} for periodic sampling"
71
66
  end
72
67
  rescue NewRelic::Agent::Sampler::Unsupported => e
73
- log.info "#{subclass} sampler not available: #{e}"
68
+ ::NewRelic::Agent.logger.info "#{subclass} sampler not available: #{e}"
74
69
  rescue => e
75
- log.error "Error registering sampler: #{e}, #{e.backtrace.join("\n")}"
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
- log.debug "Finished instrumentation"
90
+ ::NewRelic::Agent.logger.info "Finished instrumentation"
96
91
  end
97
92
  end
98
93
  include Instrumentation
@@ -18,29 +18,27 @@ module NewRelic
18
18
  # the server we should contact for api requests, like uploading
19
19
  # deployments and the like
20
20
  def api_server
21
- api_host = self['api_host'] || 'rpm.newrelic.com'
22
- @api_server ||=
23
- NewRelic::Control::Server.new \
24
- api_host,
25
- (self['api_port'] || self['port'] || (use_ssl? ? 443 : 80)).to_i,
26
- nil
21
+ @api_server ||= NewRelic::Control::Server.new(Agent.config[:api_host], Agent.config[:api_port], nil)
27
22
  end
28
23
 
29
24
  # a new instances of the proxy server - this passes through if
30
25
  # there is no proxy, otherwise it has proxy configuration
31
26
  # information pulled from the config file
32
27
  def proxy_server
33
- @proxy_server ||=
34
- NewRelic::Control::ProxyServer.new self['proxy_host'], self['proxy_port'], self['proxy_user'], self['proxy_pass']
28
+ @proxy_server ||= NewRelic::Control::ProxyServer.new(Agent.config[:proxy_host],
29
+ Agent.config[:proxy_port],
30
+ Agent.config[:proxy_user],
31
+ Agent.config[:proxy_pass])
35
32
  end
36
33
 
37
34
  # turns a hostname into an ip address and returns a
38
35
  # NewRelic::Control::Server that contains the configuration info
39
36
  def server_from_host(hostname=nil)
40
- host = hostname || self['host'] || 'collector.newrelic.com'
37
+ host = hostname || Agent.config[:host]
41
38
 
42
39
  # if the host is not an IP address, turn it into one
43
- NewRelic::Control::Server.new host, (self['port'] || (use_ssl? ? 443 : 80)).to_i, convert_to_ip_address(host)
40
+ NewRelic::Control::Server.new(host, Agent.config[:port],
41
+ convert_to_ip_address(host))
44
42
  end
45
43
 
46
44
  # Check to see if we need to look up the IP address
@@ -50,10 +48,11 @@ module NewRelic
50
48
  def convert_to_ip_address(host)
51
49
  # here we leave it as a host name since the cert verification
52
50
  # needs it in host form
53
- return host if verify_certificate?
51
+ return host if Agent.config[:ssl] && Agent.config[:verify_certificate]
54
52
  return nil if host.nil? || host.downcase == "localhost"
55
53
  ip = resolve_ip_address(host)
56
- log.info "Resolved #{host} to #{ip}"
54
+
55
+ ::NewRelic::Agent.logger.debug "Resolved #{host} to #{ip}"
57
56
  ip
58
57
  end
59
58
 
@@ -64,13 +63,12 @@ module NewRelic
64
63
  def resolve_ip_address(host)
65
64
  Resolv.getaddress(host)
66
65
  rescue => e
67
- log.warn("DNS Error caching IP address: #{e}")
68
- log.debug(e.backtrace.join("\n "))
66
+ ::NewRelic::Agent.logger.warn("DNS Error caching IP address:", e)
69
67
  begin
70
- log.info("Trying native DNS lookup since Resolv failed")
68
+ ::NewRelic::Agent.logger.debug("Trying native DNS lookup since Resolv failed")
71
69
  IPSocket.getaddress(host)
72
70
  rescue => e
73
- log.error("Could not look up server address: #{e}")
71
+ ::NewRelic::Agent.logger.error("Could not look up server address: #{e}")
74
72
  nil
75
73
  end
76
74
  end
@@ -94,10 +92,10 @@ module NewRelic
94
92
  http_class = Net::HTTP::Proxy(proxy_server.name, proxy_server.port,
95
93
  proxy_server.user, proxy_server.password)
96
94
  http = http_class.new(host.ip || host.name, host.port)
97
- log.debug("Http Connection opened to #{host.ip||host.name}:#{host.port}")
98
- if use_ssl?
95
+ ::NewRelic::Agent.logger.debug("Http Connection opened to #{host.ip||host.name}:#{host.port}")
96
+ if Agent.config[:ssl]
99
97
  http.use_ssl = true
100
- if verify_certificate?
98
+ if Agent.config[:verify_certificate]
101
99
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
102
100
  http.ca_file = cert_file_path
103
101
  else
@@ -15,12 +15,12 @@ DependencyDetection.defer do
15
15
  @name = :delayed_job_injection
16
16
 
17
17
  depends_on do
18
- defined?(::Delayed) && defined?(::Delayed::Worker) && !NewRelic::Control.instance['disable_dj']
18
+ defined?(::Delayed) && defined?(::Delayed::Worker) && !NewRelic::Agent.config[:disable_dj]
19
19
  end
20
20
 
21
21
  executes do
22
22
  if NewRelic::Agent.respond_to?(:logger)
23
- NewRelic::Agent.logger.debug 'Installing DelayedJob instrumentation hooks'
23
+ ::NewRelic::Agent.logger.info 'Installing DelayedJob instrumentation hooks'
24
24
  end
25
25
  end
26
26
 
@@ -0,0 +1,34 @@
1
+ module NewRelic
2
+ # A singleton for shared generic helper methods
3
+ module Helper
4
+ extend self
5
+
6
+ # confirm a string is correctly encoded (in >= 1.9)
7
+ # If not force the encoding to ASCII-8BIT (binary)
8
+ if RUBY_VERSION >= '1.9'
9
+ def correctly_encoded(string)
10
+ return string unless string.is_a? String
11
+ string.valid_encoding? ? string : string.force_encoding("ASCII-8BIT")
12
+ end
13
+ else
14
+ #noop
15
+ def correctly_encoded(string)
16
+ string
17
+ end
18
+ end
19
+
20
+ def instance_method_visibility(klass, method_name)
21
+ if klass.private_instance_methods.map{|s|s.to_sym}.include? method_name.to_sym
22
+ :private
23
+ elsif klass.protected_instance_methods.map{|s|s.to_sym}.include? method_name.to_sym
24
+ :protected
25
+ else
26
+ :public
27
+ end
28
+ end
29
+
30
+ def time_to_millis(time)
31
+ (time.to_f * 1000).round
32
+ end
33
+ end
34
+ end
@@ -1,28 +1,6 @@
1
1
  module NewRelic::LanguageSupport
2
2
  extend self
3
-
4
- module DataSerialization
5
- def self.included(base)
6
- # need to disable GC during marshal load in 1.8.7
7
- if NewRelic::LanguageSupport.using_version?('1.8.7') &&
8
- !NewRelic::LanguageSupport.using_engine?('jruby') &&
9
- !NewRelic::LanguageSupport.using_engine?('rbx')
10
- base.class_eval do
11
- def self.load(*args)
12
- if defined?(::GC) && ::GC.respond_to?(:disable)
13
- ::GC.disable
14
- val = super
15
- ::GC.enable
16
- val
17
- else
18
- super
19
- end
20
- end
21
- end
22
- end
23
- end
24
- end
25
-
3
+
26
4
  module Control
27
5
  def self.included(base)
28
6
  # need to use syck rather than psych when possible
@@ -43,21 +21,22 @@ module NewRelic::LanguageSupport
43
21
  end
44
22
  end
45
23
  end
46
-
47
- module SynchronizedHash
48
- def self.included(base)
49
- # need to lock iteration of stats hash in 1.9.x
50
- if NewRelic::LanguageSupport.using_version?('1.9') ||
51
- NewRelic::LanguageSupport.using_engine?('jruby')
52
- base.class_eval do
53
- def each(*args, &block)
54
- @lock.synchronize { super }
55
- end
56
- end
57
- end
24
+
25
+ @@forkable = nil
26
+ def can_fork?
27
+ # this is expensive to check, so we should only check once
28
+ return @@forkable if @@forkable != nil
29
+
30
+ if Process.respond_to?(:fork)
31
+ # if this is not 1.9.2 or higher, we have to make sure
32
+ @@forkable = ::RUBY_VERSION < '1.9.2' ? test_forkability : true
33
+ else
34
+ @@forkable = false
58
35
  end
36
+
37
+ @@forkable
59
38
  end
60
-
39
+
61
40
  def using_engine?(engine)
62
41
  if defined?(::RUBY_ENGINE)
63
42
  ::RUBY_ENGINE == engine
@@ -65,9 +44,49 @@ module NewRelic::LanguageSupport
65
44
  engine == 'ruby'
66
45
  end
67
46
  end
68
-
47
+
48
+ def broken_gc?
49
+ NewRelic::LanguageSupport.using_version?('1.8.7') &&
50
+ RUBY_PATCHLEVEL < 348 &&
51
+ !NewRelic::LanguageSupport.using_engine?('jruby') &&
52
+ !NewRelic::LanguageSupport.using_engine?('rbx')
53
+ end
54
+
55
+ def with_disabled_gc
56
+ if defined?(::GC) && ::GC.respond_to?(:disable)
57
+ val = nil
58
+ begin
59
+ ::GC.disable
60
+ val = yield
61
+ ensure
62
+ ::GC.enable
63
+ end
64
+ val
65
+ else
66
+ yield
67
+ end
68
+ end
69
+
70
+ def with_cautious_gc
71
+ if broken_gc?
72
+ with_disabled_gc { yield }
73
+ else
74
+ yield
75
+ end
76
+ end
77
+
69
78
  def using_version?(version)
70
79
  numbers = version.split('.')
71
80
  numbers == ::RUBY_VERSION.split('.')[0, numbers.size]
72
81
  end
82
+
83
+ def test_forkability
84
+ child = Process.fork { exit! }
85
+ # calling wait here doesn't seem like it should necessary, but it seems to
86
+ # resolve some weird edge cases with resque forking.
87
+ Process.wait child
88
+ true
89
+ rescue NotImplementedError
90
+ false
91
+ end
73
92
  end
@@ -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
  #
@@ -14,17 +13,17 @@ module NewRelic
14
13
  #
15
14
  # NewRelic::LocalEnvironment should be accessed through NewRelic::Control#env (via the NewRelic::Control singleton).
16
15
  class LocalEnvironment
17
-
18
16
  # mongrel, thin, webrick, or possibly nil
19
- attr_accessor :dispatcher
17
+ def discovered_dispatcher
18
+ discover_dispatcher unless @discovered_dispatcher
19
+ @discovered_dispatcher
20
+ end
21
+
20
22
  # used to distinguish instances of a dispatcher from each other, may be nil
21
23
  attr_writer :dispatcher_instance_id
22
- # rails, rails3, merb, external, ruby, test, etc
23
- attr_accessor :framework
24
24
  # The number of cpus, if detected, or nil - many platforms do not
25
25
  # support this :(
26
- attr_reader :processors
27
- alias environment dispatcher
26
+ attr_reader :processors
28
27
 
29
28
  def initialize
30
29
  # Extend self with any any submodules of LocalEnvironment. These can override
@@ -34,9 +33,7 @@ module NewRelic
34
33
  self.extend mod if mod.instance_of? Module
35
34
  end
36
35
 
37
- discover_framework
38
36
  discover_dispatcher
39
- @dispatcher = nil if @dispatcher == :none
40
37
  @gems = Set.new
41
38
  @plugins = Set.new
42
39
  @config = Hash.new
@@ -49,9 +46,8 @@ module NewRelic
49
46
  def append_environment_value(name, value = nil)
50
47
  value = yield if block_given?
51
48
  @config[name] = value if value
52
- rescue
53
- # puts "#{e}\n #{e.backtrace.join("\n ")}"
54
- raise if @framework == :test
49
+ rescue => e
50
+ Agent.logger.error e
55
51
  end
56
52
 
57
53
  # yields to the block and appends the returned value to the list
@@ -59,24 +55,22 @@ module NewRelic
59
55
  def append_gem_list
60
56
  @gems += yield
61
57
  rescue => e
62
- # puts "#{e}\n #{e.backtrace.join("\n ")}"
63
- raise if @framework == :test
58
+ Agent.logger.error e
64
59
  end
65
60
 
66
61
  # yields to the block and appends the returned value to the list
67
62
  # of plugins - this catches errors that might be raised in the block
68
63
  def append_plugin_list
69
64
  @plugins += yield
70
- rescue
71
- # puts "#{e}\n #{e.backtrace.join("\n ")}"
72
- raise if @framework == :test
65
+ rescue => e
66
+ Agent.logger.error e
73
67
  end
74
68
 
75
69
  # An instance id pulled from either @dispatcher_instance_id or by
76
70
  # splitting out the first part of the running file
77
71
  def dispatcher_instance_id
78
72
  if @dispatcher_instance_id.nil?
79
- if @dispatcher.nil?
73
+ if @discovered_dispatcher.nil?
80
74
  @dispatcher_instance_id = File.basename($0).split(".").first
81
75
  end
82
76
  end
@@ -123,7 +117,7 @@ module NewRelic
123
117
 
124
118
  if processors == 0
125
119
  processors = 1 # assume there is at least one processor
126
- 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}")
127
121
  end
128
122
  processors
129
123
  end
@@ -198,8 +192,8 @@ module NewRelic
198
192
  # Collect base statistics about the environment and record them for
199
193
  # comparison and change detection.
200
194
  def gather_environment_info
201
- append_environment_value 'Framework', @framework.to_s
202
- append_environment_value 'Dispatcher', @dispatcher.to_s if @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]
203
197
  append_environment_value 'Dispatcher instance id', @dispatcher_instance_id if @dispatcher_instance_id
204
198
  append_environment_value('Environment') { NewRelic::Control.instance.env }
205
199
 
@@ -245,47 +239,19 @@ module NewRelic
245
239
 
246
240
  private
247
241
 
248
- # Although you can override the framework with NEWRELIC_DISPATCHER this
242
+ # Although you can override the dispatcher with NEWRELIC_DISPATCHER this
249
243
  # is not advisable since it implies certain api's being available.
250
244
  def discover_dispatcher
251
- @dispatcher ||= ENV['NEWRELIC_DISPATCHER'] && ENV['NEWRELIC_DISPATCHER'].to_sym
252
- @dispatcher ||= ENV['NEW_RELIC_DISPATCHER'] && ENV['NEW_RELIC_DISPATCHER'].to_sym
253
245
  dispatchers = %w[passenger torquebox glassfish thin mongrel litespeed webrick fastcgi unicorn sinatra]
254
- while dispatchers.any? && @dispatcher.nil?
246
+ while dispatchers.any? && @discovered_dispatcher.nil?
255
247
  send 'check_for_'+(dispatchers.shift)
256
248
  end
257
249
  end
258
250
 
259
- def discover_framework
260
- # Although you can override the framework with NEWRELIC_FRAMEWORK this
261
- # is not advisable since it implies certain api's being available.
262
- #
263
- # Note that the odd defined? sequence is necessary to work around a bug in an older version
264
- # of JRuby.
265
- @framework ||= case
266
- when ENV['NEWRELIC_FRAMEWORK'] then ENV['NEWRELIC_FRAMEWORK'].to_sym
267
- when ENV['NEW_RELIC_FRAMEWORK'] then ENV['NEW_RELIC_FRAMEWORK'].to_sym
268
- when defined?(::NewRelic::TEST) then :test
269
- when defined?(::Merb) && defined?(::Merb::Plugins) then :merb
270
- when defined?(::Rails) then check_rails_version
271
- when defined?(::Sinatra) && defined?(::Sinatra::Base) then :sinatra
272
- when defined?(::NewRelic::IA) then :external
273
- else :ruby
274
- end
275
- end
276
-
277
- def check_rails_version
278
- if Rails::VERSION::MAJOR < 3
279
- :rails
280
- else
281
- :rails3
282
- end
283
- end
284
-
285
251
  def check_for_torquebox
286
252
  return unless defined?(::JRuby) &&
287
253
  ( org.torquebox::TorqueBox rescue nil)
288
- @dispatcher = :torquebox
254
+ @discovered_dispatcher = :torquebox
289
255
  end
290
256
 
291
257
  def check_for_glassfish
@@ -293,12 +259,12 @@ module NewRelic
293
259
  (((com.sun.grizzly.jruby.rack.DefaultRackApplicationFactory rescue nil) &&
294
260
  defined?(com::sun::grizzly::jruby::rack::DefaultRackApplicationFactory)) ||
295
261
  (jruby_rack? && defined?(::GlassFish::Server)))
296
- @dispatcher = :glassfish
262
+ @discovered_dispatcher = :glassfish
297
263
  end
298
264
 
299
265
  def check_for_trinidad
300
266
  return unless defined?(::JRuby) && jruby_rack? && defined?(::Trinidad::Server)
301
- @dispatcher = :trinidad
267
+ @discovered_dispatcher = :trinidad
302
268
  end
303
269
 
304
270
  def jruby_rack?
@@ -308,7 +274,7 @@ module NewRelic
308
274
 
309
275
  def check_for_webrick
310
276
  return unless defined?(::WEBrick) && defined?(::WEBrick::VERSION)
311
- @dispatcher = :webrick
277
+ @discovered_dispatcher = :webrick
312
278
  if defined?(::OPTIONS) && OPTIONS.respond_to?(:fetch)
313
279
  # OPTIONS is set by script/server
314
280
  @dispatcher_instance_id = OPTIONS.fetch(:port)
@@ -318,13 +284,13 @@ module NewRelic
318
284
 
319
285
  def check_for_fastcgi
320
286
  return unless defined?(::FCGI)
321
- @dispatcher = :fastcgi
287
+ @discovered_dispatcher = :fastcgi
322
288
  end
323
289
 
324
290
  # this case covers starting by mongrel_rails
325
291
  def check_for_mongrel
326
292
  return unless defined?(::Mongrel) && defined?(::Mongrel::HttpServer)
327
- @dispatcher = :mongrel
293
+ @discovered_dispatcher = :mongrel
328
294
 
329
295
  # Get the port from the server if it's started
330
296
 
@@ -346,7 +312,7 @@ module NewRelic
346
312
  def check_for_unicorn
347
313
  if (defined?(::Unicorn) && defined?(::Unicorn::HttpServer)) && working_jruby?
348
314
  v = find_class_in_object_space(::Unicorn::HttpServer)
349
- @dispatcher = :unicorn if v
315
+ @discovered_dispatcher = :unicorn if v
350
316
  end
351
317
  end
352
318
 
@@ -363,7 +329,7 @@ module NewRelic
363
329
  $stderr.puts("Your Sinatra version is #{version}, we highly recommend upgrading to >=0.9.2")
364
330
  end
365
331
 
366
- @dispatcher = :sinatra
332
+ @discovered_dispatcher = :sinatra
367
333
  end
368
334
 
369
335
  def check_for_thin
@@ -371,7 +337,7 @@ module NewRelic
371
337
  # This case covers the thin web dispatcher
372
338
  # Same issue as above- we assume only one instance per process
373
339
  ObjectSpace.each_object(Thin::Server) do |thin_dispatcher|
374
- @dispatcher = :thin
340
+ @discovered_dispatcher = :thin
375
341
  backend = thin_dispatcher.backend
376
342
  # We need a way to uniquely identify and distinguish agents. The port
377
343
  # works for this. When using sockets, use the socket file name.
@@ -384,21 +350,21 @@ module NewRelic
384
350
  end
385
351
  end # each thin instance
386
352
  end
387
- if defined?(::Thin) && defined?(::Thin::VERSION) && !@dispatcher
388
- @dispatcher = :thin
353
+ if defined?(::Thin) && defined?(::Thin::VERSION) && !@discovered_dispatcher
354
+ @discovered_dispatcher = :thin
389
355
  @dispatcher_instance_id = default_port
390
356
  end
391
357
  end
392
358
 
393
359
  def check_for_litespeed
394
360
  if caller.pop =~ /fcgi-bin\/RailsRunner\.rb/
395
- @dispatcher = :litespeed
361
+ @discovered_dispatcher = :litespeed
396
362
  end
397
363
  end
398
364
 
399
365
  def check_for_passenger
400
- if (defined?(::Passenger) && defined?(::Passenger::AbstractServer)) || defined?(::IN_PHUSION_PASSENGER)
401
- @dispatcher = :passenger
366
+ if defined?(::PhusionPassenger)
367
+ @discovered_dispatcher = :passenger
402
368
  end
403
369
  end
404
370
 
@@ -418,8 +384,7 @@ module NewRelic
418
384
  # outputs a human-readable description
419
385
  def to_s
420
386
  s = "LocalEnvironment["
421
- s << @framework.to_s
422
- s << ";dispatcher=#{@dispatcher}" if @dispatcher
387
+ s << ";dispatcher=#{@discovered_dispatcher}" if @discovered_dispatcher
423
388
  s << ";instance=#{@dispatcher_instance_id}" if @dispatcher_instance_id
424
389
  s << "]"
425
390
  end