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
@@ -23,7 +23,7 @@ class NewRelic::Agent::StatsEngineTest < Minitest::Test
23
23
 
24
24
  def populate_container(engine, n)
25
25
  n.times do |i|
26
- engine.record_metrics("metric#{i}", i)
26
+ engine.tl_record_unscoped_metrics("metric#{i}", i)
27
27
  end
28
28
  end
29
29
 
@@ -98,7 +98,7 @@ class NewRelic::Agent::StatsHashTest < Minitest::Test
98
98
  hash2 = NewRelic::Agent::StatsHash.new
99
99
  hash2.record(specs[0], 1)
100
100
  hash2.record(specs[1], 2)
101
- hash2.record(specs[3], 3) # no scope
101
+ hash2.record(specs[3], 3)
102
102
 
103
103
  hash1.merge!(hash2)
104
104
 
@@ -120,6 +120,33 @@ class NewRelic::Agent::StatsHashTest < Minitest::Test
120
120
  assert_equal(t0.to_f, hash1.started_at)
121
121
  end
122
122
 
123
+ def test_merge_transaction_metrics
124
+ specs = [
125
+ NewRelic::MetricSpec.new('foo'),
126
+ NewRelic::MetricSpec.new('bar'),
127
+ NewRelic::MetricSpec.new('baz'),
128
+ NewRelic::MetricSpec.new('baz', 'a_scope')
129
+ ]
130
+
131
+ hash = NewRelic::Agent::StatsHash.new
132
+ hash.record(specs[0], 1)
133
+ hash.record(specs[1], 2)
134
+ hash.record(specs[2], 3)
135
+
136
+ txn_metrics = NewRelic::Agent::TransactionMetrics.new
137
+ txn_metrics.record_unscoped(specs[0].name, 1)
138
+ txn_metrics.record_unscoped(specs[1].name, 2)
139
+ txn_metrics.record_scoped(specs[3].name, 3)
140
+
141
+ hash.merge_transaction_metrics!(txn_metrics, 'a_scope')
142
+
143
+ assert_equal(4, hash.keys.size)
144
+ assert_equal(2, hash[specs[0]].call_count)
145
+ assert_equal(2, hash[specs[1]].call_count)
146
+ assert_equal(1, hash[specs[2]].call_count)
147
+ assert_equal(1, hash[specs[3]].call_count)
148
+ end
149
+
123
150
  def test_marshal_dump
124
151
  @hash.record('foo', 1)
125
152
  @hash.record('bar', 2)
@@ -61,7 +61,7 @@ class NewRelic::Agent::StatsTest < Minitest::Test
61
61
  def test_to_s
62
62
  s1 = NewRelic::Agent::Stats.new
63
63
  s1.trace_call 10
64
- assert_equal("[ 1 calls 10.0000s]", s1.to_s)
64
+ assert_equal("[ 1 calls 10.0000s / 10.0000s ex]", s1.to_s)
65
65
  end
66
66
 
67
67
  def test_apdex_recording
@@ -117,17 +117,6 @@ class NewRelic::Agent::StatsTest < Minitest::Test
117
117
  validate s2, 1, 20, 20, 20, 10
118
118
  end
119
119
 
120
- def test_merge_array
121
- s1 = NewRelic::Agent::Stats.new
122
- merges = []
123
- merges << (NewRelic::Agent::Stats.new.trace_call 1)
124
- merges << (NewRelic::Agent::Stats.new.trace_call 1)
125
- merges << (NewRelic::Agent::Stats.new.trace_call 1)
126
-
127
- s1.merge! merges
128
- validate s1, 3, 3, 1, 1
129
- end
130
-
131
120
  def test_freeze
132
121
  s1 = NewRelic::Agent::Stats.new
133
122
 
@@ -9,18 +9,21 @@ module NewRelic::Agent::Threading
9
9
  class AgentThreadTest < Minitest::Test
10
10
 
11
11
  def test_sets_label
12
- t = AgentThread.new("labelled") {}
12
+ t = AgentThread.create("labelled") {}
13
13
  assert_equal "labelled", t[:newrelic_label]
14
+ t.join
14
15
  end
15
16
 
16
17
  def test_bucket_thread_as_agent_when_profiling
17
- t = AgentThread.new("labelled") {}
18
+ t = AgentThread.create("labelled") {}
18
19
  assert_equal :agent, AgentThread.bucket_thread(t, true)
20
+ t.join
19
21
  end
20
22
 
21
23
  def test_bucket_thread_as_agent_when_not_profiling
22
- t = AgentThread.new("labelled") {}
24
+ t = AgentThread.create("labelled") {}
23
25
  assert_equal :ignore, AgentThread.bucket_thread(t, false)
26
+ t.join
24
27
  end
25
28
 
26
29
  def test_bucket_thread_as_request
@@ -28,10 +31,15 @@ module NewRelic::Agent::Threading
28
31
  q1 = Queue.new
29
32
 
30
33
  t = Thread.new do
31
- in_transaction do |txn|
32
- txn.request = 'whatever'
34
+ begin
35
+ in_transaction do |txn|
36
+ txn.request = 'whatever'
37
+ q0.push 'unblock main thread'
38
+ q1.pop
39
+ end
40
+ rescue => e
33
41
  q0.push 'unblock main thread'
34
- q1.pop
42
+ fail e
35
43
  end
36
44
  end
37
45
 
@@ -47,9 +55,14 @@ module NewRelic::Agent::Threading
47
55
  q1 = Queue.new
48
56
 
49
57
  t = ::Thread.new do
50
- in_transaction do
58
+ begin
59
+ in_transaction do
60
+ q0.push 'unblock main thread'
61
+ q1.pop
62
+ end
63
+ rescue => e
51
64
  q0.push 'unblock main thread'
52
- q1.pop
65
+ fail e
53
66
  end
54
67
  end
55
68
 
@@ -63,12 +76,13 @@ module NewRelic::Agent::Threading
63
76
  def test_bucket_thread_as_other
64
77
  t = ::Thread.new {}
65
78
  assert_equal :other, AgentThread.bucket_thread(t, DONT_CARE)
79
+ t.join
66
80
  end
67
81
 
68
82
  def test_runs_block
69
83
  called = false
70
84
 
71
- t = AgentThread.new("labelled") { called = true }
85
+ t = AgentThread.create("labelled") { called = true }
72
86
  t.join
73
87
 
74
88
  assert called
@@ -61,7 +61,7 @@ if NewRelic::Agent::Threading::BacktraceService.is_supported?
61
61
  def test_stop_clears_buffered_backtraces
62
62
  fake_worker_loop(@service)
63
63
 
64
- thread = fake_thread(:bucket => :request)
64
+ thread = fake_thread(:request)
65
65
 
66
66
  @service.subscribe('foo')
67
67
  @service.poll
@@ -121,10 +121,10 @@ if NewRelic::Agent::Threading::BacktraceService.is_supported?
121
121
  def test_poll_forwards_backtraces_to_subscribed_profiles
122
122
  fake_worker_loop(@service)
123
123
 
124
- bt0, bt1 = mock('bt0'), mock('bt1')
124
+ bt0, bt1 = ["bt0"], ["bt1"]
125
125
 
126
- thread0 = fake_thread(:bucket => :request, :backtrace => bt0)
127
- thread1 = fake_thread(:bucket => :differenter_request, :backtrace => bt1)
126
+ thread0 = fake_thread(:request, bt0)
127
+ thread1 = fake_thread(:differenter_request, bt1)
128
128
 
129
129
  profile = @service.subscribe(BacktraceService::ALL_TRANSACTIONS)
130
130
  profile.expects(:aggregate).with(bt0, :request, thread0)
@@ -136,7 +136,7 @@ if NewRelic::Agent::Threading::BacktraceService.is_supported?
136
136
  def test_poll_does_not_forward_ignored_backtraces_to_profiles
137
137
  fake_worker_loop(@service)
138
138
 
139
- fake_thread(:bucket => :ignore)
139
+ fake_thread(:ignore)
140
140
 
141
141
  profile = @service.subscribe(BacktraceService::ALL_TRANSACTIONS)
142
142
  profile.expects(:aggregate).never
@@ -146,13 +146,13 @@ if NewRelic::Agent::Threading::BacktraceService.is_supported?
146
146
 
147
147
  def test_poll_scrubs_backtraces_before_forwarding_to_profiles
148
148
  fake_worker_loop(@service)
149
- raw_backtrace = mock('raw')
150
- scrubbed_backtrace = mock('scrubbed')
149
+ scrubbed_backtrace = []
151
150
 
152
- thread = fake_thread(
153
- :bucket => :agent,
154
- :backtrace => raw_backtrace,
155
- :scrubbed_backtrace => scrubbed_backtrace)
151
+ thread = fake_thread(:agent, ["trace"])
152
+
153
+ AgentThread.stubs(:scrub_backtrace).
154
+ with(thread, any_parameters).
155
+ returns(scrubbed_backtrace)
156
156
 
157
157
  profile = @service.subscribe(BacktraceService::ALL_TRANSACTIONS)
158
158
  profile.expects(:aggregate).with(scrubbed_backtrace, :agent, thread)
@@ -163,7 +163,7 @@ if NewRelic::Agent::Threading::BacktraceService.is_supported?
163
163
  def test_poll_records_supportability_metrics
164
164
  fake_worker_loop(@service)
165
165
 
166
- fake_thread(:bucket => :request)
166
+ fake_thread(:request)
167
167
 
168
168
  profile = @service.subscribe(BacktraceService::ALL_TRANSACTIONS)
169
169
  profile.stubs(:aggregate)
@@ -233,13 +233,13 @@ if NewRelic::Agent::Threading::BacktraceService.is_supported?
233
233
  end
234
234
 
235
235
  def test_sample_thread_does_not_backtrace_if_no_subscriptions
236
- thread = fake_thread(:bucket => :request)
236
+ thread = fake_thread(:request)
237
237
  thread.expects(:backtrace).never
238
238
  @service.sample_thread(thread)
239
239
  end
240
240
 
241
241
  def test_sample_thread_does_not_backtrace_if_ignored
242
- thread = fake_thread(:bucket => :ignore)
242
+ thread = fake_thread(:ignore)
243
243
  thread.expects(:backtrace).never
244
244
  @service.sample_thread(thread)
245
245
  end
@@ -248,7 +248,7 @@ if NewRelic::Agent::Threading::BacktraceService.is_supported?
248
248
  fake_worker_loop(@service)
249
249
  @service.subscribe('foo')
250
250
 
251
- thread = fake_thread(:bucket => :other)
251
+ thread = fake_thread(:other)
252
252
  thread.expects(:backtrace).never
253
253
  @service.sample_thread(thread)
254
254
  end
@@ -256,7 +256,7 @@ if NewRelic::Agent::Threading::BacktraceService.is_supported?
256
256
  def test_on_transaction_finished_always_clears_buffer_for_current_thread
257
257
  fake_worker_loop(@service)
258
258
 
259
- thread = fake_thread(:bucket => :request)
259
+ thread = fake_thread(:request)
260
260
  @service.subscribe('foo')
261
261
  @service.poll
262
262
 
@@ -267,7 +267,7 @@ if NewRelic::Agent::Threading::BacktraceService.is_supported?
267
267
  def test_on_transaction_finished_aggregates_backtraces_to_subscribed_profile
268
268
  fake_worker_loop(@service)
269
269
 
270
- thread = fake_thread(:bucket => :request)
270
+ thread = fake_thread(:request)
271
271
  profile = @service.subscribe('foo')
272
272
 
273
273
  t0 = Time.now
@@ -280,7 +280,7 @@ if NewRelic::Agent::Threading::BacktraceService.is_supported?
280
280
  def test_on_transaction_finished_does_not_aggregate_backtraces_to_non_subscribed_profiles
281
281
  fake_worker_loop(@service)
282
282
 
283
- thread = fake_thread(:bucket => :request)
283
+ thread = fake_thread(:request)
284
284
  profile = @service.subscribe('foo')
285
285
 
286
286
  t0 = Time.now
@@ -293,8 +293,8 @@ if NewRelic::Agent::Threading::BacktraceService.is_supported?
293
293
  def test_on_transaction_finished_delivers_buffered_backtraces_for_correct_thread
294
294
  fake_worker_loop(@service)
295
295
 
296
- thread0 = fake_thread(:bucket => :request)
297
- thread1 = fake_thread(:bucket => :request)
296
+ thread0 = fake_thread(:request)
297
+ thread1 = fake_thread(:request)
298
298
 
299
299
  profile = @service.subscribe('foo')
300
300
 
@@ -311,7 +311,7 @@ if NewRelic::Agent::Threading::BacktraceService.is_supported?
311
311
  def test_on_transaction_finished_only_delivers_backtraces_within_transaction_time_window
312
312
  fake_worker_loop(@service)
313
313
 
314
- thread = fake_thread(:bucket => :request)
314
+ thread = fake_thread(:request)
315
315
 
316
316
  profile = @service.subscribe('foo')
317
317
 
@@ -328,7 +328,7 @@ if NewRelic::Agent::Threading::BacktraceService.is_supported?
328
328
  def test_does_not_deliver_non_request_backtraces_to_subscribed_profiles
329
329
  fake_worker_loop(@service)
330
330
 
331
- thread = fake_thread(:bucket => :other)
331
+ thread = fake_thread(:other)
332
332
 
333
333
  profile = @service.subscribe('foo')
334
334
 
@@ -342,7 +342,7 @@ if NewRelic::Agent::Threading::BacktraceService.is_supported?
342
342
  def test_subscribe_sets_up_transaction_finished_subscription
343
343
  fake_worker_loop(@service)
344
344
 
345
- Thread.current[:bucket] = :request
345
+ mark_bucket_for_thread(Thread.current, :request)
346
346
  FakeThread.list << Thread.current
347
347
 
348
348
  profile = @service.subscribe('foo')
@@ -352,8 +352,6 @@ if NewRelic::Agent::Threading::BacktraceService.is_supported?
352
352
 
353
353
  profile.expects(:aggregate).once
354
354
  fake_transaction_finished('foo', t0.to_f, 1.0)
355
- ensure
356
- Thread.current[:bucket] = nil
357
355
  end
358
356
 
359
357
  def test_service_increments_profile_poll_counts
@@ -370,8 +368,8 @@ if NewRelic::Agent::Threading::BacktraceService.is_supported?
370
368
 
371
369
  def test_poll_scrubs_dead_threads_from_buffer
372
370
  fake_worker_loop(@service)
373
- thread0 = fake_thread(:bucket => :request)
374
- thread1 = fake_thread(:bucket => :request)
371
+ thread0 = fake_thread(:request)
372
+ thread1 = fake_thread(:request)
375
373
 
376
374
  @service.subscribe('foo')
377
375
  @service.poll
@@ -492,14 +490,17 @@ if NewRelic::Agent::Threading::BacktraceService.is_supported?
492
490
  dummy_loop
493
491
  end
494
492
 
495
- def fake_thread(opts={})
496
- defaults = {
497
- :backtrace => mock('backtrace')
498
- }
499
- thread = FakeThread.new(defaults.merge(opts))
493
+ def fake_thread(bucket, backtrace=[])
494
+ thread = FakeThread.new(:backtrace => backtrace)
495
+ mark_bucket_for_thread(thread, bucket)
496
+
500
497
  FakeThread.list << thread
501
498
  thread
502
499
  end
500
+
501
+ def mark_bucket_for_thread(thread, bucket)
502
+ AgentThread.stubs(:bucket_thread).with(thread, any_parameters).returns(bucket)
503
+ end
503
504
  end
504
505
 
505
506
  # These tests do not use ThreadedTestCase as FakeThread is synchronous and
@@ -18,14 +18,6 @@ class FakeThread
18
18
  @@list
19
19
  end
20
20
 
21
- def self.bucket_thread(thread, _)
22
- thread[:bucket]
23
- end
24
-
25
- def self.scrub_backtrace(thread, _)
26
- thread[:scrubbed_backtrace] || thread.backtrace
27
- end
28
-
29
21
  def alive?
30
22
  true
31
23
  end
@@ -38,6 +30,10 @@ class FakeThread
38
30
  @locals[key]
39
31
  end
40
32
 
33
+ def []=(key, value)
34
+ @locals[key] = value
35
+ end
36
+
41
37
  def backtrace
42
38
  @locals[:backtrace] || []
43
39
  end
@@ -6,23 +6,13 @@ require 'new_relic/agent/threading/fake_thread'
6
6
 
7
7
  module ThreadedTestCase
8
8
  def setup_fake_threads
9
- @original_thread_class = NewRelic::Agent::Threading::AgentThread
10
- swap_thread_class(FakeThread)
9
+ @original_thread_class = NewRelic::Agent::Threading::AgentThread.backing_thread_class
10
+ NewRelic::Agent::Threading::AgentThread.backing_thread_class = FakeThread
11
+ FakeThread.list.clear
11
12
  end
12
13
 
13
14
  def teardown_fake_threads
14
- swap_thread_class(@original_thread_class)
15
- @original_thread_class = nil
16
-
15
+ NewRelic::Agent::Threading::AgentThread.backing_thread_class = @original_thread_class
17
16
  FakeThread.list.clear
18
17
  end
19
-
20
- private
21
-
22
- def swap_thread_class(klass)
23
- if NewRelic::Agent::Threading.const_defined?("AgentThread")
24
- NewRelic::Agent::Threading.send(:remove_const, "AgentThread")
25
- end
26
- NewRelic::Agent::Threading.const_set("AgentThread", klass)
27
- end
28
18
  end
@@ -14,11 +14,11 @@ class NewRelic::Agent::TracedMethodStackTest < Minitest::Test
14
14
  freeze_time
15
15
 
16
16
  in_transaction('orlando') do
17
- self.class.trace_execution_scoped('disney', :deduct_call_time_from_parent => false) { advance_time(0.1) }
17
+ self.class.trace_execution_scoped('disney') { advance_time(0.1) }
18
18
  end
19
19
 
20
20
  in_transaction('anaheim') do
21
- self.class.trace_execution_scoped('disney', :deduct_call_time_from_parent => false) { advance_time(0.11) }
21
+ self.class.trace_execution_scoped('disney') { advance_time(0.11) }
22
22
  end
23
23
 
24
24
  assert_metrics_recorded(
@@ -38,26 +38,30 @@ class NewRelic::Agent::TracedMethodStackTest < Minitest::Test
38
38
 
39
39
 
40
40
  def test_scope_failure
41
- scope1 = @frame_stack.push_frame(:scope1)
42
- scope2 = @frame_stack.push_frame(:scope2)
41
+ state = NewRelic::Agent::TransactionState.tl_get
42
+
43
+ scope1 = @frame_stack.push_frame(state, :scope1)
44
+ scope2 = @frame_stack.push_frame(state, :scope2)
43
45
  assert_raises(RuntimeError) do
44
- @frame_stack.pop_frame(scope1, "name 1")
46
+ @frame_stack.pop_frame(state, scope1, "name 1", Time.now.to_f)
45
47
  end
46
48
  end
47
49
 
48
50
  def test_children_time
51
+ state = NewRelic::Agent::TransactionState.tl_get
52
+
49
53
  t1 = freeze_time
50
- expected1 = @frame_stack.push_frame(:a)
54
+ expected1 = @frame_stack.push_frame(state, :a)
51
55
  advance_time(0.001)
52
56
  t2 = Time.now
53
57
 
54
- expected2 = @frame_stack.push_frame(:b)
58
+ expected2 = @frame_stack.push_frame(state, :b)
55
59
  advance_time(0.002)
56
60
  t3 = Time.now
57
61
 
58
- expected = @frame_stack.push_frame(:c)
62
+ expected = @frame_stack.push_frame(state, :c)
59
63
  advance_time(0.003)
60
- scope = @frame_stack.pop_frame(expected, "metric c")
64
+ scope = @frame_stack.pop_frame(state, expected, "metric c", Time.now.to_f)
61
65
 
62
66
  t4 = Time.now
63
67
  assert_equal 0, scope.children_time
@@ -65,20 +69,20 @@ class NewRelic::Agent::TracedMethodStackTest < Minitest::Test
65
69
  advance_time(0.001)
66
70
  t5 = Time.now
67
71
 
68
- expected = @frame_stack.push_frame(:d)
72
+ expected = @frame_stack.push_frame(state, :d)
69
73
  advance_time(0.002)
70
- scope = @frame_stack.pop_frame(expected, "metric d")
74
+ scope = @frame_stack.pop_frame(state, expected, "metric d", Time.now.to_f)
71
75
 
72
76
  t6 = Time.now
73
77
 
74
78
  assert_equal 0, scope.children_time
75
79
 
76
- scope = @frame_stack.pop_frame(expected2, "metric b")
80
+ scope = @frame_stack.pop_frame(state, expected2, "metric b", Time.now.to_f)
77
81
  assert_equal 'metric b', scope.name
78
82
 
79
83
  assert_in_delta((t4 - t3) + (t6 - t5), scope.children_time, 0.0001)
80
84
 
81
- scope = @frame_stack.pop_frame(expected1, "metric a")
85
+ scope = @frame_stack.pop_frame(state, expected1, "metric a", Time.now.to_f)
82
86
  assert_equal scope.name, 'metric a'
83
87
 
84
88
  assert_in_delta((t6 - t2), scope.children_time, 0.0001)
@@ -87,13 +91,15 @@ class NewRelic::Agent::TracedMethodStackTest < Minitest::Test
87
91
 
88
92
  # test for when the scope stack contains an element only used for tts and not metrics
89
93
  def test_simple_tt_only_scope
90
- node1 = @frame_stack.push_frame(:a, 0, true)
91
- node2 = @frame_stack.push_frame(:b, 10, false)
92
- node3 = @frame_stack.push_frame(:c, 20, true)
94
+ state = NewRelic::Agent::TransactionState.tl_get
93
95
 
94
- @frame_stack.pop_frame(node3, "name a", 30)
95
- @frame_stack.pop_frame(node2, "name b", 20)
96
- @frame_stack.pop_frame(node1, "name c", 10)
96
+ node1 = @frame_stack.push_frame(state, :a, 0)
97
+ node2 = @frame_stack.push_frame(state, :b, 10)
98
+ node3 = @frame_stack.push_frame(state, :c, 20)
99
+
100
+ @frame_stack.pop_frame(state, node3, "name a", 30)
101
+ @frame_stack.pop_frame(state, node2, "name b", 20)
102
+ @frame_stack.pop_frame(state, node1, "name c", 10)
97
103
 
98
104
  assert_equal 0, node3.children_time
99
105
  assert_equal 10, node2.children_time
@@ -103,15 +109,17 @@ class NewRelic::Agent::TracedMethodStackTest < Minitest::Test
103
109
  end
104
110
 
105
111
  def test_double_tt_only_scope
106
- node1 = @frame_stack.push_frame(:a, 0, true)
107
- node2 = @frame_stack.push_frame(:b, 10, false)
108
- node3 = @frame_stack.push_frame(:c, 20, false)
109
- node4 = @frame_stack.push_frame(:d, 30, true)
112
+ state = NewRelic::Agent::TransactionState.tl_get
113
+
114
+ node1 = @frame_stack.push_frame(state, :a, 0)
115
+ node2 = @frame_stack.push_frame(state, :b, 10)
116
+ node3 = @frame_stack.push_frame(state, :c, 20)
117
+ node4 = @frame_stack.push_frame(state, :d, 30)
110
118
 
111
- @frame_stack.pop_frame(node4, "name d", 40)
112
- @frame_stack.pop_frame(node3, "name c", 30)
113
- @frame_stack.pop_frame(node2, "name b", 20)
114
- @frame_stack.pop_frame(node1, "name a", 10)
119
+ @frame_stack.pop_frame(state, node4, "name d", 40)
120
+ @frame_stack.pop_frame(state, node3, "name c", 30)
121
+ @frame_stack.pop_frame(state, node2, "name b", 20)
122
+ @frame_stack.pop_frame(state, node1, "name a", 10)
115
123
 
116
124
  assert_equal 0, node4.children_time.round
117
125
  assert_equal 10, node3.children_time.round
@@ -121,6 +129,14 @@ class NewRelic::Agent::TracedMethodStackTest < Minitest::Test
121
129
  assert @frame_stack.empty?
122
130
  end
123
131
 
132
+ def test_clear
133
+ state = NewRelic::Agent::TransactionState.tl_get
134
+
135
+ @frame_stack.push_frame(state, :a)
136
+ @frame_stack.clear
137
+ assert_empty @frame_stack
138
+ end
139
+
124
140
  def test_sampler_enabling
125
141
  assert_sampler_enabled_with(true, :'transaction_tracer.enabled' => true, :developer_mode => false)
126
142
  assert_sampler_enabled_with(true, :'transaction_tracer.enabled' => false, :developer_mode => true)