newrelic_rpm 3.8.1.221 → 3.9.0.229

Sign up to get free protection for your applications and to get access to all the features.
Files changed (288) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.gitignore +1 -0
  3. data/.yardopts +2 -0
  4. data/CHANGELOG +95 -0
  5. data/README.md +9 -3
  6. data/Rakefile +6 -0
  7. data/lib/new_relic/agent.rb +37 -52
  8. data/lib/new_relic/agent/agent.rb +32 -64
  9. data/lib/new_relic/agent/agent_logger.rb +3 -2
  10. data/lib/new_relic/agent/audit_logger.rb +2 -1
  11. data/lib/new_relic/agent/busy_calculator.rb +10 -8
  12. data/lib/new_relic/agent/configuration.rb +0 -13
  13. data/lib/new_relic/agent/configuration/default_source.rb +27 -20
  14. data/lib/new_relic/agent/configuration/manager.rb +101 -27
  15. data/lib/new_relic/agent/cross_app_monitor.rb +43 -50
  16. data/lib/new_relic/agent/cross_app_tracing.rb +13 -12
  17. data/lib/new_relic/agent/error_collector.rb +31 -35
  18. data/lib/new_relic/agent/harvester.rb +5 -1
  19. data/lib/new_relic/agent/hostname.rb +17 -0
  20. data/lib/new_relic/agent/http_clients/curb_wrappers.rb +1 -1
  21. data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +1 -1
  22. data/lib/new_relic/agent/http_clients/uri_util.rb +13 -0
  23. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +18 -32
  24. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +15 -15
  25. data/lib/new_relic/agent/instrumentation/active_merchant.rb +1 -1
  26. data/lib/new_relic/agent/instrumentation/active_record.rb +6 -4
  27. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +3 -2
  28. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +18 -20
  29. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +79 -93
  30. data/lib/new_relic/agent/instrumentation/curb.rb +3 -3
  31. data/lib/new_relic/agent/instrumentation/data_mapper.rb +5 -4
  32. data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +96 -0
  33. data/lib/new_relic/agent/instrumentation/middleware_tracing.rb +69 -0
  34. data/lib/new_relic/agent/instrumentation/net.rb +1 -1
  35. data/lib/new_relic/agent/instrumentation/queue_time.rb +21 -13
  36. data/lib/new_relic/agent/instrumentation/rack.rb +85 -74
  37. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +3 -1
  38. data/lib/new_relic/agent/instrumentation/rails_middleware.rb +39 -0
  39. data/lib/new_relic/agent/instrumentation/rubyprof.rb +3 -3
  40. data/lib/new_relic/agent/instrumentation/sidekiq.rb +28 -5
  41. data/lib/new_relic/agent/instrumentation/sinatra.rb +4 -4
  42. data/lib/new_relic/agent/instrumentation/typhoeus.rb +4 -2
  43. data/lib/new_relic/agent/javascript_instrumentor.rb +34 -30
  44. data/lib/new_relic/agent/memory_logger.rb +12 -12
  45. data/lib/new_relic/agent/method_tracer.rb +34 -74
  46. data/lib/new_relic/agent/new_relic_service.rb +1 -1
  47. data/lib/new_relic/agent/pipe_channel_manager.rb +3 -3
  48. data/lib/new_relic/agent/request_sampler.rb +10 -11
  49. data/lib/new_relic/agent/samplers/vm_sampler.rb +6 -6
  50. data/lib/new_relic/agent/shim_agent.rb +2 -1
  51. data/lib/new_relic/agent/sql_sampler.rb +52 -27
  52. data/lib/new_relic/agent/stats.rb +24 -10
  53. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +5 -17
  54. data/lib/new_relic/agent/stats_engine/metric_stats.rb +106 -58
  55. data/lib/new_relic/agent/stats_engine/stats_hash.rb +20 -24
  56. data/lib/new_relic/agent/supported_versions.rb +3 -1
  57. data/lib/new_relic/agent/threading/agent_thread.rb +42 -11
  58. data/lib/new_relic/agent/threading/backtrace_service.rb +3 -7
  59. data/lib/new_relic/agent/threading/thread_profile.rb +2 -2
  60. data/lib/new_relic/agent/traced_method_stack.rb +28 -18
  61. data/lib/new_relic/agent/transaction.rb +249 -196
  62. data/lib/new_relic/agent/transaction_metrics.rb +57 -0
  63. data/lib/new_relic/agent/transaction_sample_builder.rb +10 -7
  64. data/lib/new_relic/agent/transaction_sampler.rb +81 -45
  65. data/lib/new_relic/agent/transaction_state.rb +38 -49
  66. data/lib/new_relic/agent/vm/monotonic_gc_profiler.rb +15 -18
  67. data/lib/new_relic/agent/vm/rubinius_vm.rb +4 -2
  68. data/lib/new_relic/cli/commands/deployments.rb +3 -2
  69. data/lib/new_relic/control/frameworks/ruby.rb +2 -3
  70. data/lib/new_relic/control/frameworks/sinatra.rb +0 -7
  71. data/lib/new_relic/control/instance_methods.rb +3 -5
  72. data/lib/new_relic/json_wrapper.rb +2 -0
  73. data/lib/new_relic/language_support.rb +1 -1
  74. data/lib/new_relic/local_environment.rb +0 -16
  75. data/lib/new_relic/metric_spec.rb +10 -38
  76. data/lib/new_relic/noticed_error.rb +16 -11
  77. data/lib/new_relic/rack/agent_hooks.rb +4 -10
  78. data/lib/new_relic/rack/agent_middleware.rb +31 -0
  79. data/lib/new_relic/rack/browser_monitoring.rb +7 -13
  80. data/lib/new_relic/rack/developer_mode.rb +16 -59
  81. data/lib/new_relic/rack/error_collector.rb +16 -54
  82. data/lib/new_relic/recipes.rb +8 -101
  83. data/lib/new_relic/recipes/capistrano3.rb +66 -0
  84. data/lib/new_relic/recipes/capistrano_legacy.rb +98 -0
  85. data/lib/new_relic/transaction_sample.rb +6 -54
  86. data/lib/new_relic/transaction_sample/composite_segment.rb +1 -1
  87. data/lib/new_relic/transaction_sample/segment.rb +12 -4
  88. data/lib/new_relic/transaction_sample/summary_segment.rb +1 -1
  89. data/lib/new_relic/version.rb +2 -2
  90. data/lib/newrelic_rpm.rb +1 -1
  91. data/lib/sequel/extensions/newrelic_instrumentation.rb +19 -19
  92. data/lib/tasks/tests.rake +20 -1
  93. data/lib/tasks/versions.html.erb +0 -4
  94. data/lib/tasks/versions.rake +4 -3
  95. data/newrelic.yml +4 -12
  96. data/newrelic_rpm.gemspec +1 -1
  97. data/test/agent_helper.rb +146 -44
  98. data/test/config/newrelic.yml +0 -1
  99. data/test/environments/norails/Gemfile +1 -1
  100. data/test/environments/rails21/Gemfile +1 -1
  101. data/test/environments/rails22/Gemfile +1 -1
  102. data/test/environments/rails23/Gemfile +1 -1
  103. data/test/environments/rails30/Gemfile +1 -1
  104. data/test/environments/rails31/Gemfile +1 -1
  105. data/test/environments/rails32/Gemfile +1 -1
  106. data/test/environments/rails40/Gemfile +1 -1
  107. data/test/environments/rails41/Gemfile +1 -1
  108. data/test/multiverse/lib/multiverse/runner.rb +13 -1
  109. data/test/multiverse/lib/multiverse/suite.rb +26 -9
  110. data/test/multiverse/suites/active_record/config/newrelic.yml +0 -1
  111. data/test/multiverse/suites/activemerchant/Envfile +18 -1
  112. data/test/multiverse/suites/agent_only/audit_log_test.rb +4 -3
  113. data/test/multiverse/suites/agent_only/collector_exception_handling_test.rb +35 -0
  114. data/test/multiverse/suites/agent_only/config/newrelic.yml +0 -1
  115. data/test/multiverse/suites/agent_only/cross_application_tracing_test.rb +1 -0
  116. data/test/multiverse/suites/agent_only/encoding_handling_test.rb +3 -2
  117. data/test/multiverse/suites/agent_only/exclusive_time_test.rb +178 -0
  118. data/test/multiverse/suites/agent_only/logging_test.rb +10 -6
  119. data/test/multiverse/suites/agent_only/marshaling_test.rb +11 -9
  120. data/test/multiverse/suites/agent_only/script/loading.rb +1 -1
  121. data/test/multiverse/suites/agent_only/service_timeout_test.rb +5 -1
  122. data/test/multiverse/suites/agent_only/transaction_ignoring_test.rb +2 -1
  123. data/test/multiverse/suites/agent_only/xray_sessions_test.rb +9 -9
  124. data/test/multiverse/suites/capistrano/Capfile +26 -0
  125. data/test/multiverse/suites/capistrano/Envfile +18 -0
  126. data/test/multiverse/suites/capistrano/config/deploy.rb +10 -0
  127. data/test/multiverse/suites/capistrano/config/deploy/production.rb +9 -0
  128. data/test/multiverse/suites/capistrano/config/newrelic.yml +21 -0
  129. data/test/multiverse/suites/capistrano/deployment_test.rb +47 -0
  130. data/test/multiverse/suites/capistrano2/Capfile +4 -0
  131. data/test/multiverse/suites/capistrano2/Envfile +4 -0
  132. data/test/multiverse/suites/capistrano2/config/deploy.rb +19 -0
  133. data/test/multiverse/suites/capistrano2/config/newrelic.yml +21 -0
  134. data/test/multiverse/suites/capistrano2/deployment_test.rb +38 -0
  135. data/test/multiverse/suites/curb/Envfile +10 -1
  136. data/test/multiverse/suites/curb/config/newrelic.yml +0 -1
  137. data/test/multiverse/suites/datamapper/config/newrelic.yml +0 -1
  138. data/test/multiverse/suites/deferred_instrumentation/config/newrelic.yml +0 -1
  139. data/test/multiverse/suites/excon/config/newrelic.yml +0 -1
  140. data/test/multiverse/suites/httpclient/config/newrelic.yml +0 -1
  141. data/test/multiverse/suites/mongo/config/newrelic.yml +0 -1
  142. data/test/multiverse/suites/net_http/config/newrelic.yml +0 -1
  143. data/test/multiverse/suites/padrino/config/newrelic.yml +0 -1
  144. data/test/multiverse/suites/rack/Envfile +25 -0
  145. data/test/multiverse/suites/rack/example_app.rb +50 -0
  146. data/test/multiverse/suites/rack/nested_non_rack_app_test.rb +66 -0
  147. data/test/multiverse/suites/rack/rack_auto_instrumentation_test.rb +143 -0
  148. data/test/multiverse/suites/rack/rack_unsupported_version_test.rb +45 -0
  149. data/test/multiverse/suites/rack/url_map_test.rb +120 -0
  150. data/test/multiverse/suites/rails/Envfile +10 -0
  151. data/test/multiverse/suites/rails/app.rb +28 -63
  152. data/test/multiverse/suites/rails/bad_instrumentation_test.rb +2 -4
  153. data/test/multiverse/suites/rails/config/newrelic.yml +1 -2
  154. data/test/multiverse/suites/rails/dummy.txt +1 -0
  155. data/test/multiverse/suites/rails/error_tracing_test.rb +46 -31
  156. data/test/multiverse/suites/rails/gc_instrumentation_test.rb +0 -1
  157. data/test/multiverse/suites/rails/ignore_test.rb +9 -3
  158. data/test/multiverse/suites/rails/middleware_instrumentation_test.rb +41 -0
  159. data/test/multiverse/suites/rails/middlewares.rb +19 -0
  160. data/test/multiverse/suites/rails/parameter_capture_test.rb +169 -0
  161. data/test/multiverse/suites/rails/queue_time_test.rb +14 -4
  162. data/test/multiverse/suites/rails/rails2_app/app/controllers/application.rb +7 -0
  163. data/test/multiverse/suites/rails/rails2_app/config/boot.rb +127 -0
  164. data/test/multiverse/suites/rails/rails2_app/config/database.yml +18 -0
  165. data/test/multiverse/suites/rails/rails2_app/config/environment.rb +16 -0
  166. data/test/multiverse/suites/rails/rails2_app/config/environments/development.rb +10 -0
  167. data/test/multiverse/suites/rails/rails2_app/config/initializers/load_newrelic_rpm.rb +9 -0
  168. data/test/multiverse/suites/rails/rails2_app/config/preinitializer.rb +25 -0
  169. data/test/multiverse/suites/rails/rails2_app/config/routes.rb +18 -0
  170. data/test/multiverse/suites/rails/rails2_app/db/schema.rb +5 -0
  171. data/test/multiverse/suites/rails/rails3_app/app_rails3_plus.rb +76 -0
  172. data/test/multiverse/suites/rails/request_statistics_test.rb +2 -4
  173. data/test/multiverse/suites/rails/transaction_ignoring_test.rb +3 -5
  174. data/test/multiverse/suites/rails/view_instrumentation_test.rb +73 -42
  175. data/test/multiverse/suites/resque/config/newrelic.yml +0 -1
  176. data/test/multiverse/suites/sequel/config/newrelic.yml +0 -1
  177. data/test/multiverse/suites/sidekiq/Envfile +4 -0
  178. data/test/multiverse/suites/sidekiq/after_suite.rb +7 -0
  179. data/test/multiverse/suites/sidekiq/config/newrelic.yml +0 -1
  180. data/test/multiverse/suites/sidekiq/sidekiq_instrumentation_test.rb +55 -34
  181. data/test/multiverse/suites/sidekiq/sidekiq_server.rb +30 -0
  182. data/test/multiverse/suites/sidekiq/test_worker.rb +60 -0
  183. data/test/multiverse/suites/sinatra/config/newrelic.yml +0 -1
  184. data/test/multiverse/suites/sinatra/ignoring_test.rb +33 -11
  185. data/test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb +3 -1
  186. data/test/multiverse/suites/typhoeus/Envfile +9 -0
  187. data/test/multiverse/suites/typhoeus/config/newrelic.yml +0 -1
  188. data/test/multiverse/suites/typhoeus/typhoeus_test.rb +10 -0
  189. data/test/multiverse/test/suite_examples/one/a/config/newrelic.yml +0 -1
  190. data/test/multiverse/test/suite_examples/one/b/config/newrelic.yml +0 -1
  191. data/test/new_relic/agent/agent/connect_test.rb +3 -10
  192. data/test/new_relic/agent/agent_logger_test.rb +24 -6
  193. data/test/new_relic/agent/agent_test.rb +7 -8
  194. data/test/new_relic/agent/agent_test_controller.rb +2 -2
  195. data/test/new_relic/agent/audit_logger_test.rb +5 -1
  196. data/test/new_relic/agent/busy_calculator_test.rb +1 -1
  197. data/test/new_relic/agent/configuration/manager_test.rb +68 -69
  198. data/test/new_relic/agent/cross_app_monitor_test.rb +32 -14
  199. data/test/new_relic/agent/cross_app_tracing_test.rb +2 -2
  200. data/test/new_relic/agent/error_collector/notice_error_test.rb +9 -33
  201. data/test/new_relic/agent/error_collector_test.rb +45 -14
  202. data/test/new_relic/agent/harvester_test.rb +9 -0
  203. data/test/new_relic/agent/hostname_test.rb +41 -0
  204. data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +27 -19
  205. data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +1 -1
  206. data/test/new_relic/agent/instrumentation/active_record_test.rb +3 -3
  207. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +95 -14
  208. data/test/new_relic/agent/instrumentation/middleware_proxy_test.rb +189 -0
  209. data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +2 -2
  210. data/test/new_relic/agent/instrumentation/queue_time_test.rb +18 -1
  211. data/test/new_relic/agent/instrumentation/rack_test.rb +10 -1
  212. data/test/new_relic/agent/instrumentation/sinatra_test.rb +3 -1
  213. data/test/new_relic/agent/javascript_instrumentor_test.rb +28 -41
  214. data/test/new_relic/agent/memory_logger_test.rb +14 -0
  215. data/test/new_relic/agent/method_interrobang_test.rb +1 -1
  216. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +1 -30
  217. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +5 -21
  218. data/test/new_relic/agent/method_tracer_test.rb +5 -4
  219. data/test/new_relic/agent/mock_scope_listener.rb +2 -2
  220. data/test/new_relic/agent/obfuscator_test.rb +1 -1
  221. data/test/new_relic/agent/pipe_channel_manager_test.rb +17 -5
  222. data/test/new_relic/agent/request_sampler_test.rb +16 -16
  223. data/test/new_relic/agent/rpm_agent_test.rb +23 -29
  224. data/test/new_relic/agent/sql_sampler_test.rb +39 -31
  225. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +189 -117
  226. data/test/new_relic/agent/stats_engine_test.rb +1 -1
  227. data/test/new_relic/agent/stats_hash_test.rb +28 -1
  228. data/test/new_relic/agent/stats_test.rb +1 -12
  229. data/test/new_relic/agent/threading/agent_thread_test.rb +23 -9
  230. data/test/new_relic/agent/threading/backtrace_service_test.rb +33 -32
  231. data/test/new_relic/agent/threading/fake_thread.rb +4 -8
  232. data/test/new_relic/agent/threading/threaded_test_case.rb +4 -14
  233. data/test/new_relic/agent/traced_method_stack_test.rb +43 -27
  234. data/test/new_relic/agent/transaction_interrobang_test.rb +1 -1
  235. data/test/new_relic/agent/transaction_metrics_test.rb +113 -0
  236. data/test/new_relic/agent/transaction_sample_builder_test.rb +1 -61
  237. data/test/new_relic/agent/transaction_sampler_test.rb +176 -228
  238. data/test/new_relic/agent/transaction_state_test.rb +62 -26
  239. data/test/new_relic/agent/transaction_test.rb +198 -80
  240. data/test/new_relic/agent/vm/monotonic_gc_profiler_test.rb +4 -4
  241. data/test/new_relic/agent/vm/rubinius_vm_test.rb +68 -0
  242. data/test/new_relic/agent_test.rb +31 -27
  243. data/test/new_relic/cli/commands/deployments_test.rb +7 -2
  244. data/test/new_relic/control/instance_methods_test.rb +4 -4
  245. data/test/new_relic/control_test.rb +28 -22
  246. data/test/new_relic/dependency_detection_test.rb +14 -0
  247. data/test/new_relic/fake_external_server.rb +1 -0
  248. data/test/new_relic/fake_rpm_site.rb +35 -0
  249. data/test/new_relic/http_client_test_cases.rb +12 -3
  250. data/test/new_relic/json_wrapper_test.rb +5 -0
  251. data/test/new_relic/language_support_test.rb +7 -0
  252. data/test/new_relic/license_test.rb +11 -5
  253. data/test/new_relic/local_environment_test.rb +0 -18
  254. data/test/new_relic/metric_data_test.rb +2 -2
  255. data/test/new_relic/metric_spec_test.rb +4 -23
  256. data/test/new_relic/multiverse_helpers.rb +1 -3
  257. data/test/new_relic/noticed_error_test.rb +6 -22
  258. data/test/new_relic/rack/agent_hooks_test.rb +5 -1
  259. data/test/new_relic/rack/agent_middleware_test.rb +32 -0
  260. data/test/new_relic/rack/browser_monitoring_test.rb +14 -1
  261. data/test/new_relic/rack/developer_mode_helper_test.rb +0 -8
  262. data/test/new_relic/rack/developer_mode_test.rb +1 -1
  263. data/test/new_relic/rack/error_collector_test.rb +6 -30
  264. data/test/new_relic/transaction_sample/fake_segment_test.rb +2 -2
  265. data/test/new_relic/transaction_sample/segment_test.rb +47 -47
  266. data/test/new_relic/transaction_sample_test.rb +9 -8
  267. data/test/performance/lib/performance/instrumentation/stackprof.rb +11 -8
  268. data/test/performance/script/runner +13 -0
  269. data/test/performance/suites/config.rb +5 -2
  270. data/test/performance/suites/rack_middleware.rb +84 -0
  271. data/test/performance/suites/rum_autoinsertion.rb +1 -1
  272. data/test/performance/suites/thread_profiling.rb +1 -1
  273. data/test/test_helper.rb +12 -10
  274. data/ui/helpers/developer_mode_helper.rb +3 -43
  275. data/ui/views/layouts/newrelic_default.rhtml +2 -2
  276. data/ui/views/newrelic/_sample.rhtml +2 -2
  277. data/ui/views/newrelic/_sql_row.rhtml +11 -11
  278. data/ui/views/newrelic/index.rhtml +21 -22
  279. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +15 -10
  280. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser.rb +2 -0
  281. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/middleware.rb +34 -0
  282. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/nested.rb +24 -0
  283. metadata +108 -31
  284. metadata.gz.sig +0 -0
  285. data/lib/new_relic/rack/transaction_reset.rb +0 -20
  286. data/test/multiverse/suites/rails/mongrel_queue_depth_test.rb +0 -42
  287. data/test/new_relic/rack/transaction_reset_test.rb +0 -35
  288. data/ui/views/newrelic/show_source.rhtml +0 -3
@@ -33,19 +33,19 @@ module NewRelic::Agent
33
33
  NewRelic::Agent.instance.events.clear
34
34
  @response = {}
35
35
 
36
- @monitor = NewRelic::Agent::CrossAppMonitor.new()
36
+ @monitor = NewRelic::Agent::CrossAppMonitor.new
37
37
  @config = {
38
- :cross_process_id => AGENT_CROSS_APP_ID,
39
- :encoding_key => ENCODING_KEY_NOOP,
38
+ :cross_process_id => AGENT_CROSS_APP_ID,
39
+ :encoding_key => ENCODING_KEY_NOOP,
40
40
  :trusted_account_ids => TRUSTED_ACCOUNT_IDS
41
41
  }
42
42
 
43
- NewRelic::Agent.config.apply_config( @config )
43
+ NewRelic::Agent.config.add_config_for_testing(@config)
44
44
  @monitor.on_finished_configuring
45
45
  end
46
46
 
47
47
  def teardown
48
- NewRelic::Agent.config.remove_config( @config )
48
+ NewRelic::Agent.config.remove_config(@config)
49
49
  NewRelic::Agent.instance.events.clear
50
50
  end
51
51
 
@@ -179,15 +179,33 @@ module NewRelic::Agent
179
179
  end
180
180
 
181
181
  def test_setting_response_headers_freezes_transaction_name
182
- request = for_id(REQUEST_CROSS_APP_ID)
183
- event_listener = NewRelic::Agent.instance.events
184
- event_listener.notify(:before_call, request)
185
-
186
182
  in_transaction do
187
- assert !NewRelic::Agent::Transaction.current.name_frozen?
183
+ request = for_id(REQUEST_CROSS_APP_ID)
184
+ event_listener = NewRelic::Agent.instance.events
185
+ event_listener.notify(:before_call, request)
186
+
187
+ assert !NewRelic::Agent::Transaction.tl_current.name_frozen?
188
188
  event_listener.notify(:after_call, request, [200, @response, ''])
189
- assert NewRelic::Agent::Transaction.current.name_frozen?
189
+ assert NewRelic::Agent::Transaction.tl_current.name_frozen?
190
+ end
191
+ end
192
+
193
+ def test_listener_in_other_thread_has_correct_txn_state
194
+ t = Thread.new do
195
+ event_listener = NewRelic::Agent.instance.events
196
+ in_transaction('transaction') do
197
+ request = for_id(REQUEST_CROSS_APP_ID)
198
+
199
+ event_listener.notify(:before_call, request)
200
+ # Fake out our GUID for easier comparison in tests
201
+ NewRelic::Agent::Transaction.tl_current.stubs(:guid).returns(TRANSACTION_GUID)
202
+ event_listener.notify(:after_call, request, [200, @response, ''])
203
+ end
190
204
  end
205
+
206
+ t.join
207
+
208
+ assert_metrics_recorded(["ClientApplication/#{REQUEST_CROSS_APP_ID}/all"])
191
209
  end
192
210
 
193
211
  #
@@ -196,12 +214,12 @@ module NewRelic::Agent
196
214
 
197
215
  def when_request_runs(request=for_id(REQUEST_CROSS_APP_ID))
198
216
  event_listener = NewRelic::Agent.instance.events
199
- event_listener.notify(:before_call, request)
200
217
  in_transaction('transaction') do
218
+ event_listener.notify(:before_call, request)
201
219
  # Fake out our GUID for easier comparison in tests
202
- NewRelic::Agent::Transaction.current.stubs(:guid).returns(TRANSACTION_GUID)
220
+ NewRelic::Agent::Transaction.tl_current.stubs(:guid).returns(TRANSACTION_GUID)
221
+ event_listener.notify(:after_call, request, [200, @response, ''])
203
222
  end
204
- event_listener.notify(:after_call, request, [200, @response, ''])
205
223
  end
206
224
 
207
225
  def when_request_has_error(request=for_id(REQUEST_CROSS_APP_ID))
@@ -26,7 +26,7 @@ module NewRelic
26
26
  end
27
27
 
28
28
  def test_start_trace_has_time_even_on_agent_failure
29
- NewRelic::Agent::TracedMethodStack.stubs(:push_frame).raises("Boom!")
29
+ NewRelic::Agent::TracedMethodStack.stubs(:tl_push_frame).raises("Boom!")
30
30
  t0, segment = CrossAppTracing.start_trace(request)
31
31
  refute_nil t0
32
32
  assert_nil segment
@@ -54,7 +54,7 @@ module NewRelic
54
54
 
55
55
 
56
56
  def expects_pop_frame
57
- NewRelic::Agent::TracedMethodStack.stubs(:pop_frame).once
57
+ NewRelic::Agent::TracedMethodStack.stubs(:tl_pop_frame).once
58
58
  end
59
59
  end
60
60
  end
@@ -85,29 +85,6 @@ class NewRelic::Agent::ErrorCollector::NoticeErrorTest < Minitest::Test
85
85
  end
86
86
  end
87
87
 
88
- def test_extract_source_base
89
- with_config(:'error_collector.capture_source' => true) do
90
- error_collector = NewRelic::Agent::ErrorCollector.new
91
- error_collector.expects(:sense_method).with(nil, 'source_extract')
92
- assert_equal(nil, error_collector.extract_source(nil))
93
- end
94
- end
95
-
96
- def test_extract_source_disabled
97
- with_config(:'error_collector.capture_source' => false) do
98
- error_collector = NewRelic::Agent::ErrorCollector.new
99
- assert_equal(nil, error_collector.extract_source(mock('exception')))
100
- end
101
- end
102
-
103
- def test_extract_source_with_source
104
- with_config(:'error_collector.capture_source' => true) do
105
- error_collector = NewRelic::Agent::ErrorCollector.new
106
- error_collector.expects(:sense_method).with('happy', 'source_extract').returns('THE SOURCE')
107
- assert_equal('THE SOURCE', error_collector.extract_source('happy'))
108
- end
109
- end
110
-
111
88
  def test_extract_stack_trace
112
89
  exception = mock('exception')
113
90
  self.expects(:sense_method).with(exception, 'original_exception')
@@ -138,9 +115,8 @@ class NewRelic::Agent::ErrorCollector::NoticeErrorTest < Minitest::Test
138
115
  exception = mock('exception')
139
116
  self.expects(:sense_method).with(exception, 'file_name').returns('file_name')
140
117
  self.expects(:sense_method).with(exception, 'line_number').returns('line_number')
141
- self.expects(:extract_source).with(exception).returns('source')
142
118
  self.expects(:extract_stack_trace).with(exception).returns('stack_trace')
143
- assert_equal({:file_name => 'file_name', :line_number => 'line_number', :source => 'source', :stack_trace => 'stack_trace'},
119
+ assert_equal({:file_name => 'file_name', :line_number => 'line_number', :stack_trace => 'stack_trace'},
144
120
  exception_info(exception))
145
121
  end
146
122
 
@@ -164,34 +140,34 @@ class NewRelic::Agent::ErrorCollector::NoticeErrorTest < Minitest::Test
164
140
  assert_equal([], @errors)
165
141
  end
166
142
 
167
- def test_should_exit_notice_error_disabled
143
+ def test_skip_notice_error_is_true_if_the_error_collector_is_disabled
168
144
  error = mocked_error
169
145
  with_error_collector_config(:'error_collector.enabled' => false) do |error_collector|
170
- assert error_collector.should_exit_notice_error?(error)
146
+ assert error_collector.skip_notice_error?(error)
171
147
  end
172
148
  end
173
149
 
174
- def test_should_exit_notice_error_nil
150
+ def test_skip_notice_error_is_true_if_the_error_is_nil
175
151
  error = nil
176
152
  with_error_collector_config(:'error_collector.enabled' => true) do |error_collector|
177
153
  error_collector.expects(:error_is_ignored?).with(error).returns(false)
178
- assert error_collector.should_exit_notice_error?(error)
154
+ assert error_collector.skip_notice_error?(error)
179
155
  end
180
156
  end
181
157
 
182
- def test_should_exit_notice_error_positive
158
+ def test_skip_notice_error_is_true_if_the_error_is_ignored
183
159
  error = mocked_error
184
160
  with_error_collector_config(:'error_collector.enabled' => true) do |error_collector|
185
161
  error_collector.expects(:error_is_ignored?).with(error).returns(true)
186
- assert error_collector.should_exit_notice_error?(error)
162
+ assert error_collector.skip_notice_error?(error)
187
163
  end
188
164
  end
189
165
 
190
- def test_should_exit_notice_error_negative
166
+ def test_skip_notice_error_returns_false_for_non_nil_unignored_errors_with_an_enabled_error_collector
191
167
  error = mocked_error
192
168
  with_error_collector_config(:'error_collector.enabled' => true) do |error_collector|
193
169
  error_collector.expects(:error_is_ignored?).with(error).returns(false)
194
- assert !error_collector.should_exit_notice_error?(error)
170
+ assert !error_collector.skip_notice_error?(error)
195
171
  end
196
172
  end
197
173
 
@@ -9,19 +9,19 @@ require 'new_relic/agent/internal_agent_error'
9
9
  class NewRelic::Agent::ErrorCollectorTest < Minitest::Test
10
10
  def setup
11
11
  @test_config = { :capture_params => true }
12
- NewRelic::Agent.config.apply_config(@test_config)
12
+ NewRelic::Agent.config.add_config_for_testing(@test_config)
13
13
 
14
14
  @error_collector = NewRelic::Agent::ErrorCollector.new
15
15
  @error_collector.stubs(:enabled).returns(true)
16
16
 
17
- NewRelic::Agent::TransactionState.clear
17
+ NewRelic::Agent::TransactionState.tl_clear_for_testing
18
18
  NewRelic::Agent.instance.stats_engine.reset!
19
19
  end
20
20
 
21
21
  def teardown
22
22
  super
23
- NewRelic::Agent::TransactionState.clear
24
- NewRelic::Agent.config.remove_config(@test_config)
23
+ NewRelic::Agent::TransactionState.tl_clear_for_testing
24
+ NewRelic::Agent.config.reset_to_defaults
25
25
  end
26
26
 
27
27
  # Helpers for DataContainerTests
@@ -57,7 +57,6 @@ class NewRelic::Agent::ErrorCollectorTest < Minitest::Test
57
57
  assert_equal '', err.params[:request_referer]
58
58
  assert_equal 'path', err.path
59
59
  assert_equal 'Error', err.exception_class_name
60
- assert_equal String, err.exception_class_constant
61
60
  end
62
61
 
63
62
  def test_simple
@@ -73,7 +72,6 @@ class NewRelic::Agent::ErrorCollectorTest < Minitest::Test
73
72
  assert_equal '/myurl/', err.params[:request_uri]
74
73
  assert_equal 'test_referer', err.params[:request_referer]
75
74
  assert_equal 'path', err.path
76
- assert_equal StandardError, err.exception_class_constant
77
75
  assert_equal 'StandardError', err.exception_class_name
78
76
 
79
77
  # the collector should now return an empty array since nothing
@@ -175,7 +173,7 @@ class NewRelic::Agent::ErrorCollectorTest < Minitest::Test
175
173
  def test_exclude_later_config_changes
176
174
  @error_collector.notice_error(IOError.new("message"))
177
175
 
178
- NewRelic::Agent.config.apply_config(:'error_collector.ignore_errors' => "IOError")
176
+ NewRelic::Agent.config.add_config_for_testing(:'error_collector.ignore_errors' => "IOError")
179
177
  @error_collector.notice_error(IOError.new("message"))
180
178
 
181
179
  errors = @error_collector.harvest!
@@ -195,6 +193,18 @@ class NewRelic::Agent::ErrorCollectorTest < Minitest::Test
195
193
  assert_equal 1, errors.length
196
194
  end
197
195
 
196
+ def test_failure_in_exclude_block
197
+ @error_collector.ignore_error_filter do
198
+ raise "HAHAHAHAH, error in the filter for ignoring errors!"
199
+ end
200
+
201
+ @error_collector.notice_error(StandardError.new("message"))
202
+
203
+ errors = @error_collector.harvest!
204
+
205
+ assert_equal 1, errors.length
206
+ end
207
+
198
208
  def test_obfuscates_error_messages_when_high_security_is_set
199
209
  with_config(:high_security => true) do
200
210
  @error_collector.notice_error(StandardError.new("YO SQL BAD: serect * flom test where foo = 'bar'"))
@@ -296,7 +306,7 @@ class NewRelic::Agent::ErrorCollectorTest < Minitest::Test
296
306
  @error_collector.notice_agent_error(exception)
297
307
 
298
308
  assert_equal 21, @error_collector.errors.size
299
- assert_equal DifficultToDebugAgentError, @error_collector.errors.last.exception_class_constant
309
+ assert_equal DifficultToDebugAgentError.name, @error_collector.errors.last.exception_class_name
300
310
  end
301
311
 
302
312
  def test_notice_agent_error_doesnt_clog_up_the_queue_limit
@@ -317,17 +327,38 @@ class NewRelic::Agent::ErrorCollectorTest < Minitest::Test
317
327
  assert err.message.include?("Ruby agent internal error")
318
328
  end
319
329
 
320
- def test_blamed_metric_from_options
321
- assert_equal "Errors/boo", @error_collector.blamed_metric_name(:metric => "boo")
330
+ def test_blamed_metric_from_options_outside_txn
331
+ @error_collector.notice_error(StandardError.new('wut'), :metric => 'boo')
332
+ assert_metrics_recorded(
333
+ 'Errors/boo' => { :call_count => 1}
334
+ )
335
+ end
336
+
337
+ def test_blamed_metric_from_options_inside_txn
338
+ in_transaction('Not/What/Youre/Looking/For') do
339
+ @error_collector.notice_error(StandardError.new('wut'), :metric => 'boo')
340
+ end
341
+ assert_metrics_recorded_exclusive(
342
+ {
343
+ 'Errors/all' => { :call_count => 1 },
344
+ 'Errors/boo' => { :call_count => 1 }
345
+ },
346
+ :filter => /^Errors\//
347
+ )
322
348
  end
323
349
 
324
350
  def test_blamed_metric_from_transaction
325
- NewRelic::Agent::TransactionState.get.most_recent_transaction = stub(:name => "Controller/foo/bar")
326
- assert_equal "Errors/Controller/foo/bar", @error_collector.blamed_metric_name({})
351
+ in_transaction('Controller/foo/bar') do
352
+ @error_collector.notice_error(StandardError.new('wut'))
353
+ end
354
+ assert_metrics_recorded(
355
+ 'Errors/Controller/foo/bar' => { :call_count => 1 }
356
+ )
327
357
  end
328
358
 
329
- def test_blamed_metric_with_no_transaction
330
- assert_nil @error_collector.blamed_metric_name({})
359
+ def test_blamed_metric_with_no_transaction_and_no_options
360
+ @error_collector.notice_error(StandardError.new('wut'))
361
+ assert_metrics_recorded_exclusive(['Errors/all'])
331
362
  end
332
363
 
333
364
  private
@@ -64,6 +64,15 @@ module NewRelic
64
64
  end
65
65
  end
66
66
 
67
+ def test_doesnt_call_to_restart_if_harvest_thread_disabled
68
+ pretend_started_in_another_process
69
+ @after_forker.expects(:after_fork).never
70
+
71
+ with_config(:disable_harvest_thread => true) do
72
+ harvester.on_transaction
73
+ end
74
+ end
75
+
67
76
  def test_calls_to_restart_only_once
68
77
  pretend_started_in_another_process
69
78
  @after_forker.expects(:after_fork).once
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
+
5
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
6
+ require 'new_relic/agent/hostname'
7
+
8
+ module NewRelic
9
+ module Agent
10
+ class HostnameTest < MiniTest::Unit::TestCase
11
+ def test_get_returns_socket_hostname
12
+ Socket.stubs(:gethostname).returns('Rivendell')
13
+ assert_equal 'Rivendell', NewRelic::Agent::Hostname.get
14
+ end
15
+
16
+ def test_get_uses_dyno_name_if_dyno_env_set_and_dyno_names_enabled
17
+ with_config(:use_heroku_dyno_names => true) do
18
+ Socket.stubs(:gethostname).returns('Rivendell')
19
+ ENV['DYNO'] = 'Imladris'
20
+
21
+ expected = 'Imladris'
22
+ assert_equal expected, NewRelic::Agent::Hostname.get
23
+ end
24
+ ensure
25
+ ENV.delete('DYNO')
26
+ end
27
+
28
+ def test_get_uses_socket_gethostname_if_dyno_env_set_and_dyno_names_disabled
29
+ with_config(:use_heroku_dyno_names => false) do
30
+ Socket.stubs(:gethostname).returns('Rivendell')
31
+ ENV['DYNO'] = 'Imladris'
32
+
33
+ expected = 'Rivendell'
34
+ assert_equal expected, NewRelic::Agent::Hostname.get
35
+ end
36
+ ensure
37
+ ENV.delete('DYNO')
38
+ end
39
+ end
40
+ end
41
+ end
@@ -41,7 +41,7 @@ class NewRelic::Agent::Instrumentation::ActionControllerSubscriberTest < Minites
41
41
  @stats_engine = NewRelic::Agent.instance.stats_engine
42
42
  @stats_engine.clear_stats
43
43
  NewRelic::Agent.manual_start
44
- NewRelic::Agent::TransactionState.clear
44
+ NewRelic::Agent::TransactionState.tl_clear_for_testing
45
45
  end
46
46
 
47
47
  def teardown
@@ -76,7 +76,11 @@ class NewRelic::Agent::Instrumentation::ActionControllerSubscriberTest < Minites
76
76
  def test_record_apdex_metrics_with_error
77
77
  @subscriber.start('process_action.action_controller', :id, @entry_payload)
78
78
  advance_time(1.5)
79
- @exit_payload[:exception] = StandardError.new("boo")
79
+
80
+ error = StandardError.new("boo")
81
+ @exit_payload[:exception] = error
82
+ NewRelic::Agent.notice_error(error)
83
+
80
84
  @subscriber.finish('process_action.action_controller', :id, @exit_payload)
81
85
 
82
86
  expected_values = { :apdex_f => 1, :apdex_t => 0, :apdex_s => 0 }
@@ -117,14 +121,14 @@ class NewRelic::Agent::Instrumentation::ActionControllerSubscriberTest < Minites
117
121
 
118
122
  def test_sets_default_transaction_name_on_start
119
123
  @subscriber.start('process_action.action_controller', :id, @entry_payload)
120
- assert_equal 'Controller/test/index', NewRelic::Agent::Transaction.current.best_name
124
+ assert_equal 'Controller/test/index', NewRelic::Agent::Transaction.tl_current.best_name
121
125
  ensure
122
126
  @subscriber.finish('process_action.action_controller', :id, @entry_payload)
123
127
  end
124
128
 
125
129
  def test_sets_default_transaction_keeps_name_through_stop
126
130
  @subscriber.start('process_action.action_controller', :id, @entry_payload)
127
- txn = NewRelic::Agent::Transaction.current
131
+ txn = NewRelic::Agent::Transaction.tl_current
128
132
  @subscriber.finish('process_action.action_controller', :id, @entry_payload)
129
133
  assert_equal 'Controller/test/index', txn.best_name
130
134
  end
@@ -132,14 +136,14 @@ class NewRelic::Agent::Instrumentation::ActionControllerSubscriberTest < Minites
132
136
  def test_sets_transaction_name
133
137
  @subscriber.start('process_action.action_controller', :id, @entry_payload)
134
138
  NewRelic::Agent.set_transaction_name('something/else')
135
- assert_equal 'Controller/something/else', NewRelic::Agent::Transaction.current.best_name
139
+ assert_equal 'Controller/something/else', NewRelic::Agent::Transaction.tl_current.best_name
136
140
  ensure
137
141
  @subscriber.finish('process_action.action_controller', :id, @entry_payload)
138
142
  end
139
143
 
140
144
  def test_sets_transaction_name_holds_through_stop
141
145
  @subscriber.start('process_action.action_controller', :id, @entry_payload)
142
- txn = NewRelic::Agent::Transaction.current
146
+ txn = NewRelic::Agent::Transaction.tl_current
143
147
  NewRelic::Agent.set_transaction_name('something/else')
144
148
  @subscriber.finish('process_action.action_controller', :id, @entry_payload)
145
149
  assert_equal 'Controller/something/else', txn.best_name
@@ -173,9 +177,10 @@ class NewRelic::Agent::Instrumentation::ActionControllerSubscriberTest < Minites
173
177
  @entry_payload[:action] = 'ignored_enduser'
174
178
  @exit_payload[:action] = 'ignored_enduser'
175
179
  @subscriber.start('process_action.action_controller', :id, @entry_payload)
180
+ txn = NewRelic::Agent::Transaction.tl_current
176
181
  @subscriber.finish('process_action.action_controller', :id, @exit_payload)
177
182
 
178
- assert NewRelic::Agent::TransactionState.get.request_ignore_enduser
183
+ assert txn.ignore_enduser?
179
184
  end
180
185
 
181
186
  def test_record_busy_time
@@ -217,13 +222,15 @@ class NewRelic::Agent::Instrumentation::ActionControllerSubscriberTest < Minites
217
222
  end
218
223
 
219
224
  def test_record_queue_time_metrics
225
+ app = lambda do |env|
226
+ @subscriber.start('process_action.action_controller', :id, @entry_payload)
227
+ advance_time(2)
228
+ @subscriber.finish('process_action.action_controller', :id, @exit_payload)
229
+ end
230
+
220
231
  t0 = Time.now
221
232
  env = { 'HTTP_X_REQUEST_START' => (t0 - 5).to_f.to_s }
222
- NewRelic::Agent.instance.events.notify(:before_call, env)
223
-
224
- @subscriber.start('process_action.action_controller', :id, @entry_payload)
225
- advance_time(2)
226
- @subscriber.finish('process_action.action_controller', :id, @exit_payload)
233
+ ::NewRelic::Rack::AgentHooks.new(app).call(env)
227
234
 
228
235
  assert_metrics_recorded(
229
236
  'WebFrontend/QueueTime' => {
@@ -241,15 +248,16 @@ class NewRelic::Agent::Instrumentation::ActionControllerSubscriberTest < Minites
241
248
  end
242
249
 
243
250
  def test_dont_record_queue_time_in_nested_transaction
244
- t0 = Time.now
251
+ app = lambda do |env|
252
+ @subscriber.start('process_action.action_controller', :id, @entry_payload)
253
+ @subscriber.start('process_action.action_controller', :id, @entry_payload)
254
+ @subscriber.finish('process_action.action_controller', :id, @exit_payload)
255
+ @subscriber.finish('process_action.action_controller', :id, @exit_payload)
256
+ end
245
257
 
258
+ t0 = Time.now
246
259
  env = { 'HTTP_X_REQUEST_START' => (t0 - 5).to_f.to_s }
247
- NewRelic::Agent.instance.events.notify(:before_call, env)
248
-
249
- @subscriber.start('process_action.action_controller', :id, @entry_payload)
250
- @subscriber.start('process_action.action_controller', :id, @entry_payload)
251
- @subscriber.finish('process_action.action_controller', :id, @exit_payload)
252
- @subscriber.finish('process_action.action_controller', :id, @exit_payload)
260
+ ::NewRelic::Rack::AgentHooks.new(app).call(env)
253
261
 
254
262
  assert_metrics_recorded(
255
263
  'WebFrontend/QueueTime' => {