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
@@ -8,7 +8,7 @@ DependencyDetection.defer do
8
8
  end
9
9
 
10
10
  executes do
11
- NewRelic::Agent.logger.debug 'Installing ActiveMerchant instrumentation'
11
+ ::NewRelic::Agent.logger.info 'Installing ActiveMerchant instrumentation'
12
12
  end
13
13
 
14
14
  executes do
@@ -18,7 +18,8 @@ module NewRelic
18
18
  end
19
19
 
20
20
  sql, name, binds = args
21
- metric = metric_for_name(name) || metric_for_sql(sql)
21
+ metric = metric_for_name(NewRelic::Helper.correctly_encoded(name)) ||
22
+ metric_for_sql(NewRelic::Helper.correctly_encoded(sql))
22
23
 
23
24
  if !metric
24
25
  log_without_newrelic_instrumentation(*args, &block)
@@ -99,15 +100,11 @@ DependencyDetection.defer do
99
100
  end
100
101
 
101
102
  depends_on do
102
- !NewRelic::Control.instance['skip_ar_instrumentation']
103
- end
104
-
105
- depends_on do
106
- !NewRelic::Control.instance['disable_activerecord_instrumentation']
103
+ !NewRelic::Agent.config[:disable_activerecord_instrumentation]
107
104
  end
108
105
 
109
106
  executes do
110
- NewRelic::Agent.logger.debug 'Installing ActiveRecord instrumentation'
107
+ ::NewRelic::Agent.logger.info 'Installing ActiveRecord instrumentation'
111
108
  end
112
109
 
113
110
  executes do
@@ -37,7 +37,7 @@ DependencyDetection.defer do
37
37
  end
38
38
 
39
39
  executes do
40
- NewRelic::Agent.logger.debug 'Installing ActsAsSolr instrumentation'
40
+ ::NewRelic::Agent.logger.info 'Installing ActsAsSolr instrumentation'
41
41
  end
42
42
 
43
43
  executes do
@@ -8,7 +8,7 @@ DependencyDetection.defer do
8
8
  end
9
9
 
10
10
  executes do
11
- NewRelic::Agent.logger.debug 'Installing AuthLogic instrumentation'
11
+ ::NewRelic::Agent.logger.info 'Installing AuthLogic instrumentation'
12
12
  end
13
13
 
14
14
  executes do
@@ -0,0 +1,41 @@
1
+ module NewRelic
2
+ module Agent
3
+ module Instrumentation
4
+ class BrowserMonitoringTimings
5
+
6
+ def initialize(queue_time_in_seconds, transaction)
7
+ if transaction.nil?
8
+ @start_time_in_seconds = 0.0
9
+ else
10
+ @transaction_name = transaction.transaction_name
11
+ @start_time_in_seconds = transaction.start_time
12
+ end
13
+
14
+ @queue_time_in_seconds = queue_time_in_seconds
15
+ end
16
+
17
+ attr_reader :transaction_name
18
+
19
+ def start_time_in_millis
20
+ convert_to_milliseconds(@start_time_in_seconds)
21
+ end
22
+
23
+ def queue_time_in_millis
24
+ convert_to_milliseconds(@queue_time_in_seconds)
25
+ end
26
+
27
+ def app_time_in_millis
28
+ convert_to_milliseconds(Time.now - @start_time_in_seconds)
29
+ end
30
+
31
+ private
32
+
33
+ def convert_to_milliseconds(value)
34
+ value = (value.to_f * 1000.0).round
35
+ return 0.0 if value < 0
36
+ value
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -26,6 +26,7 @@ module NewRelic
26
26
  module ClassMethodsShim # :nodoc:
27
27
  def newrelic_ignore(*args); end
28
28
  def newrelic_ignore_apdex(*args); end
29
+ def newrelic_ignore_enduser(*args); end
29
30
  end
30
31
 
31
32
  module Shim # :nodoc:
@@ -51,11 +52,15 @@ module NewRelic
51
52
  newrelic_ignore_aspect('ignore_apdex', specifiers)
52
53
  end
53
54
 
55
+ def newrelic_ignore_enduser(specifiers={})
56
+ newrelic_ignore_aspect('ignore_enduser', specifiers)
57
+ end
58
+
54
59
  def newrelic_ignore_aspect(property, specifiers={}) # :nodoc:
55
60
  if specifiers.empty?
56
61
  self.newrelic_write_attr property, true
57
62
  elsif ! (Hash === specifiers)
58
- logger.error "newrelic_#{property} takes an optional hash with :only and :except lists of actions (illegal argument type '#{specifiers.class}')"
63
+ ::NewRelic::Agent.logger.error "newrelic_#{property} takes an optional hash with :only and :except lists of actions (illegal argument type '#{specifiers.class}')"
59
64
  else
60
65
  self.newrelic_write_attr property, specifiers
61
66
  end
@@ -138,16 +143,23 @@ module NewRelic
138
143
  end
139
144
  options_arg << %Q[:#{key} => #{valuestr}]
140
145
  end
146
+ traced_method, punctuation = method.to_s.sub(/([?!=])$/, ''), $1
147
+ visibility = NewRelic::Helper.instance_method_visibility self, method
148
+
141
149
  class_eval <<-EOC
142
- def #{method.to_s}_with_newrelic_transaction_trace(*args, &block)
150
+ def #{traced_method.to_s}_with_newrelic_transaction_trace#{punctuation}(*args, &block)
143
151
  perform_action_with_newrelic_trace(#{options_arg.join(',')}) do
144
- #{method.to_s}_without_newrelic_transaction_trace(*args, &block)
152
+ #{traced_method.to_s}_without_newrelic_transaction_trace#{punctuation}(*args, &block)
145
153
  end
146
154
  end
147
155
  EOC
148
- alias_method "#{method.to_s}_without_newrelic_transaction_trace", method.to_s
149
- alias_method method.to_s, "#{method.to_s}_with_newrelic_transaction_trace"
150
- NewRelic::Control.instance.log.debug("Traced transaction: class = #{self.name}, method = #{method.to_s}, options = #{options.inspect}")
156
+ without_method_name = "#{traced_method.to_s}_without_newrelic_transaction_trace#{punctuation}"
157
+ with_method_name = "#{traced_method.to_s}_with_newrelic_transaction_trace#{punctuation}"
158
+ alias_method without_method_name, method.to_s
159
+ alias_method method.to_s, with_method_name
160
+ send visibility, method
161
+ send visibility, with_method_name
162
+ ::NewRelic::Agent.logger.debug("Traced transaction: class = #{self.name}, method = #{method.to_s}, options = #{options.inspect}")
151
163
  end
152
164
  end
153
165
 
@@ -242,8 +254,9 @@ module NewRelic
242
254
  return perform_action_without_newrelic_trace(*args)
243
255
  end
244
256
  end
245
-
246
- return perform_action_with_newrelic_profile(args, &block) if NewRelic::Control.instance.profiling?
257
+
258
+ control = NewRelic::Control.instance
259
+ return perform_action_with_newrelic_profile(args, &block) if control.profiling?
247
260
 
248
261
  frame_data = _push_metric_frame(block_given? ? args : [])
249
262
  begin
@@ -251,11 +264,17 @@ module NewRelic
251
264
  frame_data.start_transaction
252
265
  begin
253
266
  NewRelic::Agent::BusyCalculator.dispatcher_start frame_data.start
254
- if block_given?
267
+ result = if block_given?
255
268
  yield
256
269
  else
257
270
  perform_action_without_newrelic_trace(*args)
258
271
  end
272
+ if defined?(request) && request && defined?(response) && response
273
+ if !Agent.config[:disable_mobile_headers]
274
+ NewRelic::Agent::BrowserMonitoring.insert_mobile_response_header(request, response)
275
+ end
276
+ end
277
+ result
259
278
  rescue => e
260
279
  frame_data.notice_error(e)
261
280
  raise
@@ -266,8 +285,9 @@ module NewRelic
266
285
  # Look for a metric frame in the thread local and process it.
267
286
  # Clear the thread local when finished to ensure it only gets called once.
268
287
  frame_data.record_apdex unless ignore_apdex?
269
-
270
288
  frame_data.pop
289
+
290
+ NewRelic::Agent::TransactionInfo.get.ignore_end_user = true if ignore_enduser?
271
291
  end
272
292
  end
273
293
 
@@ -309,6 +329,10 @@ module NewRelic
309
329
  def ignore_apdex?
310
330
  _is_filtered?('ignore_apdex')
311
331
  end
332
+
333
+ def ignore_enduser?
334
+ _is_filtered?('ignore_enduser')
335
+ end
312
336
 
313
337
  private
314
338
 
@@ -426,8 +450,7 @@ module NewRelic
426
450
  end
427
451
  queue_start || now
428
452
  rescue => e
429
- NewRelic::Control.instance.log.error("Error detecting upstream wait time: #{e}")
430
- NewRelic::Control.instance.log.debug("#{e.backtrace[0..20]}")
453
+ ::NewRelic::Agent.logger.error("Error detecting upstream wait time:", e)
431
454
  now
432
455
  end
433
456
 
@@ -57,7 +57,7 @@ DependencyDetection.defer do
57
57
  end
58
58
 
59
59
  executes do
60
- NewRelic::Agent.logger.debug 'Installing DataMapper instrumentation'
60
+ ::NewRelic::Agent.logger.info 'Installing DataMapper instrumentation'
61
61
  end
62
62
 
63
63
  executes do
@@ -180,14 +180,6 @@ module NewRelic
180
180
  module Agent
181
181
  module Instrumentation
182
182
  module DataMapperInstrumentation
183
-
184
- def self.included(klass)
185
- klass.class_eval do
186
- alias_method :log_without_newrelic_instrumentation, :log
187
- alias_method :log, :log_with_newrelic_instrumentation
188
- end
189
- end
190
-
191
183
  # Unlike in AR, log is called in DM after the query actually ran,
192
184
  # complete with metrics. Since DO has already calculated the
193
185
  # duration, there's nothing more to measure, so just record and log.
@@ -195,9 +187,9 @@ module NewRelic
195
187
  # We rely on the assumption that all possible entry points have been
196
188
  # hooked with tracers, ensuring that notice_sql attaches this SQL to
197
189
  # the proper call scope.
198
- def log_with_newrelic_instrumentation(msg)
190
+ def log(msg)
199
191
  return unless NewRelic::Agent.is_execution_traced?
200
- return unless operation = case msg.query
192
+ return unless operation = case NewRelic::Helper.correctly_encoded(msg.query)
201
193
  when /^\s*select/i then 'find'
202
194
  when /^\s*(update|insert)/i then 'save'
203
195
  when /^\s*delete/i then 'destroy'
@@ -216,7 +208,7 @@ module NewRelic
216
208
  NewRelic::Agent.instance.stats_engine.get_stats_no_scope(metric).trace_call(duration)
217
209
  end
218
210
  ensure
219
- log_without_newrelic_instrumentation(msg)
211
+ super
220
212
  end
221
213
 
222
214
  end # DataMapperInstrumentation
@@ -4,7 +4,7 @@ DependencyDetection.defer do
4
4
  @name = :delayed_job
5
5
 
6
6
  depends_on do
7
- !NewRelic::Control.instance['disable_dj']
7
+ !NewRelic::Agent.config[:disable_dj]
8
8
  end
9
9
 
10
10
  depends_on do
@@ -14,7 +14,7 @@ DependencyDetection.defer do
14
14
  end
15
15
 
16
16
  executes do
17
- NewRelic::Agent.logger.debug 'Installing DelayedJob instrumentation'
17
+ ::NewRelic::Agent.logger.info 'Installing DelayedJob instrumentation'
18
18
  end
19
19
 
20
20
  executes do
@@ -32,7 +32,7 @@ module NewRelic
32
32
  end
33
33
  end
34
34
  def memcache_key_snippet(method_name)
35
- return "" unless NewRelic::Control.instance['capture_memcache_keys']
35
+ return "" unless NewRelic::Agent.config[:capture_memcache_keys]
36
36
  "NewRelic::Agent.instance.transaction_sampler.notice_nosql(args.first.inspect, (Time.now - t0).to_f) rescue nil"
37
37
  end
38
38
  end
@@ -44,7 +44,7 @@ DependencyDetection.defer do
44
44
  @name = :memcache
45
45
 
46
46
  depends_on do
47
- !NewRelic::Control.instance['disable_memcache_instrumentation']
47
+ !NewRelic::Agent.config[:disable_memcache_instrumentation]
48
48
  end
49
49
 
50
50
  depends_on do
@@ -57,24 +57,24 @@ DependencyDetection.defer do
57
57
  if defined? ::MemCache
58
58
  NewRelic::Agent::Instrumentation::Memcache.instrument_methods(::MemCache,
59
59
  commands)
60
- NewRelic::Agent.logger.debug 'Installing MemCache instrumentation'
60
+ ::NewRelic::Agent.logger.info 'Installing MemCache instrumentation'
61
61
  end
62
62
  if defined? ::Memcached
63
63
  commands << 'cas'
64
64
  NewRelic::Agent::Instrumentation::Memcache.instrument_methods(::Memcached,
65
65
  commands)
66
- NewRelic::Agent.logger.debug 'Installing Memcached instrumentation'
66
+ ::NewRelic::Agent.logger.info 'Installing Memcached instrumentation'
67
67
  end
68
68
  if defined? ::Dalli::Client
69
69
  NewRelic::Agent::Instrumentation::Memcache.instrument_methods(::Dalli::Client,
70
70
  commands)
71
- NewRelic::Agent.logger.debug 'Installing Dalli Memcache instrumentation'
71
+ ::NewRelic::Agent.logger.info 'Installing Dalli Memcache instrumentation'
72
72
  end
73
73
  if defined? ::Spymemcached
74
74
  commands << 'multiget'
75
75
  NewRelic::Agent::Instrumentation::Memcache.instrument_methods(::Spymemcached,
76
76
  commands)
77
- NewRelic::Agent.logger.debug 'Installing Spymemcached instrumentation'
77
+ ::NewRelic::Agent.logger.info 'Installing Spymemcached instrumentation'
78
78
  end
79
79
  end
80
80
  end
@@ -8,7 +8,7 @@ DependencyDetection.defer do
8
8
  end
9
9
 
10
10
  executes do
11
- NewRelic::Agent.logger.debug 'Installing Merb Controller instrumentation'
11
+ ::NewRelic::Agent.logger.info 'Installing Merb Controller instrumentation'
12
12
  end
13
13
 
14
14
  executes do
@@ -10,7 +10,7 @@ DependencyDetection.defer do
10
10
  end
11
11
 
12
12
  executes do
13
- NewRelic::Agent.logger.debug 'Installing Merb Errors instrumentation'
13
+ ::NewRelic::Agent.logger.info 'Installing Merb Errors instrumentation'
14
14
  end
15
15
 
16
16
  executes do
@@ -27,21 +27,11 @@ module NewRelic
27
27
  attr_accessor :request
28
28
 
29
29
 
30
- @@check_server_connection = false
31
- def self.check_server_connection=(value)
32
- @@check_server_connection = value
33
- end
34
30
  # Return the currently active metric frame, or nil. Call with +true+
35
31
  # to create a new metric frame if one is not already on the thread.
36
32
  def self.current(create_if_empty=nil)
37
33
  f = Thread.current[:newrelic_metric_frame]
38
34
  return f if f || !create_if_empty
39
-
40
- # Reconnect to the server if necessary. This is only done
41
- # for old versions of passenger that don't implement an explicit after_fork
42
- # event.
43
- agent.after_fork(:keep_retrying => false) if @@check_server_connection
44
-
45
35
  Thread.current[:newrelic_metric_frame] = new
46
36
  end
47
37
 
@@ -64,8 +54,8 @@ module NewRelic
64
54
  if defined? JRuby
65
55
  begin
66
56
  require 'java'
67
- include_class 'java.lang.management.ManagementFactory'
68
- include_class 'com.sun.management.OperatingSystemMXBean'
57
+ java_import 'java.lang.management.ManagementFactory'
58
+ java_import 'com.sun.management.OperatingSystemMXBean'
69
59
  @@java_classes_loaded = true
70
60
  rescue => e
71
61
  end
@@ -263,7 +253,7 @@ module NewRelic
263
253
  end
264
254
 
265
255
  def queue_time
266
- apdex_start - start
256
+ start - apdex_start
267
257
  end
268
258
 
269
259
  def add_custom_parameters(p)
@@ -320,7 +310,7 @@ module NewRelic
320
310
  # the apdex should be recorded as a failure regardless of duration.
321
311
  def self.update_apdex(stat, duration, failed)
322
312
  duration = duration.to_f
323
- apdex_t = NewRelic::Control.instance.apdex_t
313
+ apdex_t = Agent.config[:apdex_t]
324
314
  case
325
315
  when failed
326
316
  stat.record_apdex_f
@@ -14,7 +14,7 @@ module NewRelic
14
14
  end
15
15
 
16
16
  def log_underflow
17
- NewRelic::Agent.logger.error "Underflow in metric frames: #{caller.join("\n ")}"
17
+ ::NewRelic::Agent.logger.error "Underflow in metric frames: #{caller.join("\n ")}"
18
18
  end
19
19
 
20
20
  def notice_scope_empty
@@ -6,7 +6,7 @@ DependencyDetection.defer do
6
6
  end
7
7
 
8
8
  executes do
9
- NewRelic::Agent.logger.debug 'Installing Net instrumentation'
9
+ ::NewRelic::Agent.logger.info 'Installing Net instrumentation'
10
10
  end
11
11
 
12
12
  executes do
@@ -1,19 +1,19 @@
1
1
  DependencyDetection.defer do
2
2
  @name = :passenger
3
-
3
+
4
4
  depends_on do
5
- defined?(PhusionPassenger)
5
+ defined?(::PhusionPassenger)
6
6
  end
7
7
 
8
8
  executes do
9
- NewRelic::Agent.logger.debug "Installing Passenger event hooks."
9
+ ::NewRelic::Agent.logger.debug "Installing Passenger event hooks."
10
10
 
11
- PhusionPassenger.on_event(:stopping_worker_process) do
12
- NewRelic::Agent.logger.debug "Passenger stopping this process, shutdown the agent."
11
+ ::PhusionPassenger.on_event(:stopping_worker_process) do
12
+ ::NewRelic::Agent.logger.debug "Passenger stopping this process, shutdown the agent."
13
13
  NewRelic::Agent.instance.shutdown
14
14
  end
15
15
 
16
- PhusionPassenger.on_event(:starting_worker_process) do |forked|
16
+ ::PhusionPassenger.on_event(:starting_worker_process) do |forked|
17
17
  # We want to reset the stats from the stats engine in case any carried
18
18
  # over into the spawned process. Don't clear them in case any were
19
19
  # cached. We do this even in conservative spawning.
@@ -21,17 +21,3 @@ DependencyDetection.defer do
21
21
  end
22
22
  end
23
23
  end
24
-
25
- DependencyDetection.defer do
26
- depends_on do
27
- defined?(::Passenger) && defined?(::Passenger::AbstractServer) || defined?(::IN_PHUSION_PASSENGER)
28
- end
29
-
30
- executes do
31
- ## We're on an older version of passenger
32
- ## FIXME: This warning is printing on current version of passenger
33
- # NewRelic::Agent.logger.warn "An older version of Phusion Passenger has been detected. We recommend using at least release 2.1.1."
34
-
35
- NewRelic::Agent::Instrumentation::MetricFrame.check_server_connection = true
36
- end
37
- end