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
@@ -25,7 +25,7 @@ class TransactionInterrobangTest < Minitest::Test
25
25
  assert_equal "say what?", interrogate?
26
26
  end
27
27
 
28
- def test_aliase_method_ending_in_exclamation_makr
28
+ def test_alias_method_ending_in_exclamation_mark
29
29
  assert_respond_to self, :mutate!
30
30
  assert_respond_to self, :mutate_with_newrelic_transaction_trace!
31
31
  assert_equal "oh yeah!",mutate!
@@ -0,0 +1,113 @@
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/transaction_metrics'
7
+
8
+ class TransactionMetricsTest < Minitest::Test
9
+ def setup
10
+ @metrics = NewRelic::Agent::TransactionMetrics.new
11
+ end
12
+
13
+ def test_record_scoped_should_record_a_scoped_metric
14
+ @metrics.record_scoped('foo', 42, 12)
15
+ assert_scoped_metrics(@metrics, ['foo'], {
16
+ :call_count => 1,
17
+ :total_call_time => 42,
18
+ :total_exclusive_time => 12
19
+ })
20
+ assert_unscoped_metrics(@metrics, [])
21
+ end
22
+
23
+ def test_record_scoped_should_take_multiple_metrics
24
+ @metrics.record_scoped(['foo', 'bar'], 42, 12)
25
+ assert_scoped_metrics(@metrics, ['foo', 'bar'], {
26
+ :call_count => 1,
27
+ :total_call_time => 42,
28
+ :total_exclusive_time => 12
29
+ })
30
+ assert_unscoped_metrics(@metrics, [])
31
+ end
32
+
33
+ def test_record_scoped_should_take_a_block
34
+ @metrics.record_scoped('foo') do |stats|
35
+ stats.call_count = 3
36
+ stats.total_call_time = 2
37
+ stats.total_exclusive_time = 1
38
+ end
39
+ assert_scoped_metrics(@metrics, ['foo'], {
40
+ :call_count => 3,
41
+ :total_call_time => 2,
42
+ :total_exclusive_time => 1
43
+ })
44
+ assert_unscoped_metrics(@metrics, [])
45
+ end
46
+
47
+ def test_record_unscoped_should_record_an_unscoped_metric
48
+ @metrics.record_unscoped('foo', 42, 12)
49
+ assert_unscoped_metrics(@metrics, ['foo'], {
50
+ :call_count => 1,
51
+ :total_call_time => 42,
52
+ :total_exclusive_time => 12
53
+ })
54
+ assert_scoped_metrics(@metrics, [])
55
+ end
56
+
57
+ def test_record_unscoped_should_take_multiple_metrics
58
+ @metrics.record_unscoped(['foo', 'bar'], 42, 12)
59
+ assert_unscoped_metrics(@metrics, ['foo', 'bar'], {
60
+ :call_count => 1,
61
+ :total_call_time => 42,
62
+ :total_exclusive_time => 12
63
+ })
64
+ assert_scoped_metrics(@metrics, [])
65
+ end
66
+
67
+ def test_record_unscoped_should_take_a_block
68
+ @metrics.record_unscoped('foo') do |stats|
69
+ stats.call_count = 3
70
+ stats.total_call_time = 2
71
+ stats.total_exclusive_time = 1
72
+ end
73
+ assert_unscoped_metrics(@metrics, ['foo'], {
74
+ :call_count => 3,
75
+ :total_call_time => 2,
76
+ :total_exclusive_time => 1
77
+ })
78
+ assert_scoped_metrics(@metrics, [])
79
+ end
80
+
81
+ def test_square_brackets_look_up_unscoped_metrics
82
+ @metrics.record_unscoped('foo', 42, 12)
83
+ @metrics.record_scoped('foo', 2, 1)
84
+ assert_equal(42, @metrics['foo'].total_call_time)
85
+ end
86
+
87
+ def test_has_key_checks_for_unscoped_metric_presence
88
+ refute @metrics.has_key?('foo')
89
+ end
90
+
91
+ def assert_unscoped_metrics(txn_metrics, expected_metric_names, expected_attrs={})
92
+ assert_scoped_or_unscoped_metrics(:unscoped, txn_metrics, expected_metric_names, expected_attrs)
93
+ end
94
+
95
+ def assert_scoped_metrics(txn_metrics, expected_metric_names, expected_attrs={})
96
+ assert_scoped_or_unscoped_metrics(:scoped, txn_metrics, expected_metric_names, expected_attrs)
97
+ end
98
+
99
+ def assert_scoped_or_unscoped_metrics(type, txn_metrics, expected_metric_names, expected_attrs)
100
+ names = []
101
+ all_stats = []
102
+
103
+ txn_metrics.send("each_#{type}") do |name, stats|
104
+ names << name
105
+ all_stats << stats
106
+ end
107
+
108
+ assert_equal(expected_metric_names.sort, names.sort)
109
+ names.zip(all_stats).each do |(name, stats)|
110
+ assert_stats_has_values(stats, name, expected_attrs)
111
+ end
112
+ end
113
+ end
@@ -61,66 +61,6 @@ class NewRelic::Agent::TransationSampleBuilderTest < Minitest::Test
61
61
  end
62
62
  end
63
63
 
64
- # this is really a test for transaction sample
65
- def test_omit_segments_with
66
- build_segment "Controller/my_controller/index" do
67
- advance_time 0.010
68
-
69
- build_segment "Rails/Application Code Loading" do
70
- advance_time 0.020
71
-
72
- build_segment "foo/bar" do
73
- advance_time 0.010
74
- end
75
- end
76
-
77
- build_segment "a" do
78
- build_segment "ab"
79
- advance_time 0.010
80
- end
81
- build_segment "b" do
82
- build_segment "ba"
83
- advance_time 0.05
84
- build_segment "bb"
85
- build_segment "bc" do
86
- build_segment "bca"
87
- advance_time 0.05
88
- end
89
- end
90
- build_segment "c"
91
- end
92
- @builder.finish_trace(Time.now.to_f)
93
-
94
- validate_builder false
95
-
96
- sample = @builder.sample
97
-
98
- should_be_a_copy = sample.omit_segments_with('OMIT NOTHING')
99
- validate_segment should_be_a_copy.root_segment, false
100
-
101
- assert_equal sample.params, should_be_a_copy.params
102
- assert_equal(sample.root_segment.to_debug_str(0),
103
- should_be_a_copy.root_segment.to_debug_str(0))
104
-
105
- without_code_loading = sample.omit_segments_with('Rails/Application Code Loading')
106
- validate_segment without_code_loading.root_segment, false
107
-
108
- # after we take out code loading, the delta should be approximately
109
- # 30 milliseconds
110
- delta = (sample.duration - without_code_loading.duration) * 1000
111
-
112
- # Need to allow substantial headroom on the upper bound to prevent
113
- # spurious errors.
114
- assert delta >= 28, "delta #{delta} should be between 28 and 100"
115
- # disable this test for a couple days:
116
- assert delta <= 100, "delta #{delta} should be between 28 and 100"
117
-
118
- # ensure none of the segments have this regex
119
- without_code_loading.each_segment do |segment|
120
- assert_nil segment.metric_name =~ /Rails\/Application Code Loading/
121
- end
122
- end
123
-
124
64
  def test_marshal
125
65
  build_segment "a" do
126
66
  build_segment "ab"
@@ -239,7 +179,7 @@ class NewRelic::Agent::TransationSampleBuilderTest < Minitest::Test
239
179
 
240
180
  in_transaction do
241
181
  with_config(config, :do_not_cast => true) do
242
- NewRelic::Agent::TransactionState.get.current_transaction.stubs(:apdex_t).returns(1.5)
182
+ NewRelic::Agent::TransactionState.tl_get.current_transaction.stubs(:apdex_t).returns(1.5)
243
183
  assert_equal 4.0, @builder.transaction_trace_threshold
244
184
  end
245
185
  end
@@ -26,7 +26,8 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
26
26
  end
27
27
 
28
28
  def setup
29
- NewRelic::Agent::TransactionState.clear
29
+ NewRelic::Agent::TransactionState.tl_clear_for_testing
30
+ @state = NewRelic::Agent::TransactionState.tl_get
30
31
  agent = NewRelic::Agent.instance
31
32
  stats_engine = NewRelic::Agent::StatsEngine.new
32
33
  agent.stubs(:stats_engine).returns(stats_engine)
@@ -34,13 +35,14 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
34
35
  @old_sampler = NewRelic::Agent.instance.transaction_sampler
35
36
  NewRelic::Agent.instance.instance_variable_set(:@transaction_sampler, @sampler)
36
37
  @test_config = { :'transaction_tracer.enabled' => true }
37
- NewRelic::Agent.config.apply_config(@test_config)
38
- @txn = stub('txn', :best_name => '/path', :custom_parameters => {}, :guid => 'a guid')
38
+ NewRelic::Agent.config.add_config_for_testing(@test_config)
39
+ @txn = stub('txn', :best_name => '/path', :guid => 'a guid',
40
+ :custom_parameters => {}, :filtered_params => {})
39
41
  end
40
42
 
41
43
  def teardown
42
44
  super
43
- NewRelic::Agent::TransactionState.clear
45
+ NewRelic::Agent::TransactionState.tl_clear_for_testing
44
46
  NewRelic::Agent.config.remove_config(@test_config)
45
47
  NewRelic::Agent.instance.instance_variable_set(:@transaction_sampler, @old_sampler)
46
48
  end
@@ -63,165 +65,111 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
63
65
  # Tests
64
66
 
65
67
  def test_on_start_transaction_default
66
- @sampler.expects(:start_builder).with(100.0)
67
- @sampler.on_start_transaction(Time.at(100))
68
+ @sampler.expects(:start_builder).with(@state, 100.0)
69
+ @sampler.on_start_transaction(@state, Time.at(100))
68
70
  end
69
71
 
70
72
  def test_on_start_transaction_disabled
71
73
  with_config(:'transaction_tracer.enabled' => false,
72
74
  :developer_mode => false) do
73
75
  @sampler.expects(:start_builder).never
74
- @sampler.on_start_transaction(Time.at(100))
76
+ @sampler.on_start_transaction(@state, Time.at(100))
75
77
  end
76
78
  end
77
79
 
78
80
  def test_notice_push_frame_no_builder
79
- @sampler.expects(:builder)
80
- assert_equal(nil, @sampler.notice_push_frame())
81
- end
82
-
83
- def test_notice_push_frame_with_builder
84
- with_config(:developer_mode => false) do
85
- builder = mock('builder')
86
- builder.expects(:trace_entry).with(100.0)
87
- @sampler.expects(:builder).returns(builder).twice
88
- @sampler.notice_push_frame(Time.at(100))
89
- end
81
+ assert_equal(nil, @sampler.notice_push_frame(@state))
90
82
  end
91
83
 
92
84
  def test_notice_pop_frame_no_builder
93
- @sampler.expects(:builder).returns(nil)
94
- assert_equal(nil, @sampler.notice_pop_frame('a frame', Time.at(100)))
85
+ assert_equal(nil, @sampler.notice_pop_frame(@state, 'a frame', Time.at(100)))
95
86
  end
96
87
 
97
88
  def test_notice_pop_frame_with_finished_sample
98
89
  builder = mock('builder')
99
- sample = mock('sample')
90
+ sample = mock('sample')
100
91
  builder.expects(:sample).returns(sample)
101
92
  sample.expects(:finished).returns(true)
102
- @sampler.expects(:builder).returns(builder).twice
93
+ @state.expects(:transaction_sample_builder).returns(builder)
103
94
 
104
95
  assert_raises(RuntimeError) do
105
- @sampler.notice_pop_frame('a frame', Time.at(100))
96
+ @sampler.notice_pop_frame(@state, 'a frame', Time.at(100))
106
97
  end
107
98
  end
108
99
 
109
- def test_notice_pop_frame_builder_delegation
110
- builder = mock('builder')
111
- builder.expects(:trace_exit).with('a frame', 100.0)
112
- sample = mock('sample')
113
- builder.expects(:sample).returns(sample)
114
- sample.expects(:finished).returns(false)
115
- @sampler.expects(:builder).returns(builder).times(3)
116
-
117
- @sampler.notice_pop_frame('a frame', Time.at(100))
118
- end
119
-
120
100
  def test_on_finishing_transaction_no_builder
121
- @sampler.expects(:builder).returns(nil)
122
- assert_equal(nil, @sampler.on_finishing_transaction(@txn))
123
- end
124
-
125
- def test_on_finishing_transaction_ignored_transaction
126
- builder = mock('builder')
127
- # the builder should be cached, so only called once
128
- @sampler.expects(:builder).returns(builder).once
129
-
130
- builder.expects(:finish_trace).with(100.0, {})
131
-
132
- @sampler.expects(:clear_builder)
133
-
134
- builder.expects(:ignored?).returns(true)
135
- builder.expects(:set_transaction_name).returns(true)
136
-
137
- assert_equal(nil, @sampler.on_finishing_transaction(@txn, Time.at(100)))
101
+ @state.transaction_sample_builder = nil
102
+ assert_equal(nil, @sampler.on_finishing_transaction(@state, @txn))
138
103
  end
139
104
 
140
- def test_on_finishing_transaction_with_builder
141
- builder = mock('builder')
142
- @sampler.stubs(:builder).returns(builder)
143
-
144
- builder.expects(:finish_trace).with(100.0, {})
145
- @sampler.expects(:clear_builder)
146
-
147
- builder.expects(:ignored?).returns(false)
148
- builder.expects(:set_transaction_info).returns(true)
149
- builder.expects(:set_transaction_name).returns(true)
150
-
151
- sample = mock('sample')
152
- sample.expects(:guid=)
153
- builder.expects(:sample).returns(sample)
154
- @sampler.expects(:store_sample).with(sample)
155
-
156
- @sampler.on_start_transaction(Time.now, nil, {})
157
- @sampler.on_finishing_transaction(@txn, Time.at(100))
105
+ def test_captures_correct_transaction_duration
106
+ freeze_time
107
+ in_transaction do |txn|
108
+ advance_time(10.0)
109
+ end
158
110
 
159
- assert_equal(sample, @sampler.instance_variable_get('@last_sample'))
111
+ assert_equal(10.0, @sampler.last_sample.duration)
160
112
  end
161
113
 
162
114
  def test_on_finishing_transaction_passes_guid_along
163
- builder = stub_everything('builder')
164
- @sampler.stubs(:builder).returns(builder)
165
-
166
- @txn.stubs(:guid).returns('a guid')
167
-
168
- sample = stub_everything('sample')
169
- sample.expects(:guid=).with(@txn.guid)
170
- builder.stubs(:sample).returns(sample)
115
+ in_transaction do |txn|
116
+ txn.stubs(:guid).returns('a guid')
117
+ end
171
118
 
172
- @sampler.on_start_transaction(Time.now, nil, {})
173
- @sampler.on_finishing_transaction(@txn, Time.at(100))
119
+ assert_equal('a guid', @sampler.last_sample.guid)
174
120
  end
175
121
 
176
122
  def test_ignore_transaction_no_builder
177
- @sampler.expects(:builder).returns(nil).once
178
- @sampler.ignore_transaction
123
+ ret = @sampler.ignore_transaction(@state)
124
+ assert_nil ret
179
125
  end
180
126
 
181
127
  def test_ignore_transaction_with_builder
182
- builder = mock('builder')
183
- builder.expects(:ignore_transaction)
184
- @sampler.expects(:builder).returns(builder).twice
185
- @sampler.ignore_transaction
128
+ in_transaction do
129
+ @sampler.ignore_transaction(@state)
130
+ end
131
+
132
+ assert_nil(@sampler.last_sample)
186
133
  end
187
134
 
188
- def test_notice_transaction_cpu_time_no_builder
189
- @sampler.expects(:builder).returns(nil).once
190
- @sampler.notice_transaction_cpu_time(0.0)
135
+ def test_notice_transaction_cpu_time_no_builder_does_not_crash
136
+ @state.transaction_sample_builder = nil
137
+ @sampler.notice_transaction_cpu_time(@state, 0.0)
191
138
  end
192
139
 
193
- def test_notice_transaction_cpu_time_with_builder
194
- cpu_time = mock('cpu_time')
195
- builder = mock('builder')
196
- @sampler.expects(:builder).returns(builder).twice
197
- builder.expects(:set_transaction_cpu_time).with(cpu_time)
140
+ def test_records_cpu_time_on_transaction_samples
141
+ in_transaction do |txn|
142
+ txn.stubs(:cpu_burn).returns(42)
143
+ end
198
144
 
199
- @sampler.notice_transaction_cpu_time(cpu_time)
145
+ assert_equal(42, @sampler.last_sample.params[:custom_params][:cpu_time])
200
146
  end
201
147
 
202
148
  def test_notice_extra_data_no_builder
203
- @sampler.expects(:builder).returns(nil).once
204
- @sampler.send(:notice_extra_data, nil, nil, nil)
149
+ ret = @sampler.send(:notice_extra_data, nil, nil, nil, nil)
150
+ assert_nil ret
205
151
  end
206
152
 
207
153
  def test_notice_extra_data_no_segment
208
- builder = mock('builder')
209
- @sampler.expects(:builder).returns(builder).twice
210
- builder.expects(:current_segment).returns(nil)
211
- @sampler.send(:notice_extra_data, nil, nil, nil)
154
+ mock_builder = mock('builder')
155
+ @sampler.expects(:tl_builder).returns(mock_builder).once
156
+ mock_builder.expects(:current_segment).returns(nil)
157
+ builder = @sampler.tl_builder
158
+ @sampler.send(:notice_extra_data, builder, nil, nil, nil)
212
159
  end
213
160
 
214
161
  def test_notice_extra_data_with_segment_no_old_message_no_config_key
215
162
  key = :a_key
216
- builder = mock('builder')
163
+ mock_builder = mock('builder')
217
164
  segment = mock('segment')
218
- @sampler.expects(:builder).returns(builder).twice
219
- builder.expects(:current_segment).returns(segment)
165
+ @sampler.expects(:tl_builder).returns(mock_builder).once
166
+ mock_builder.expects(:current_segment).returns(segment)
220
167
  NewRelic::Agent::TransactionSampler.expects(:truncate_message) \
221
168
  .with('a message').returns('truncated_message')
222
169
  segment.expects(:[]=).with(key, 'truncated_message')
223
170
  @sampler.expects(:append_backtrace).with(segment, 1.0)
224
- @sampler.send(:notice_extra_data, 'a message', 1.0, key)
171
+ builder = @sampler.tl_builder
172
+ @sampler.send(:notice_extra_data, builder, 'a message', 1.0, key)
225
173
  end
226
174
 
227
175
  def test_append_backtrace_under_duration
@@ -243,24 +191,28 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
243
191
  end
244
192
 
245
193
  def test_notice_sql_recording_sql
246
- NewRelic::Agent::TransactionState.get.record_sql = true
247
- @sampler.expects(:notice_extra_data).with('some sql', 1.0, :sql)
248
- @sampler.notice_sql('some sql', {:config => 'a config'}, 1.0)
194
+ @state.record_sql = true
195
+ builder = @sampler.tl_builder
196
+ @sampler.expects(:notice_extra_data).with(builder, 'some sql', 1.0, :sql)
197
+ @sampler.notice_sql('some sql', {:config => 'a config'}, 1.0, @state)
249
198
  end
250
199
 
251
200
  def test_notice_sql_not_recording
252
- NewRelic::Agent::TransactionState.get.record_sql = false
253
- @sampler.expects(:notice_extra_data).with('some sql', 1.0, :sql).never # <--- important
254
- @sampler.notice_sql('some sql', {:config => 'a config'}, 1.0)
201
+ @state.record_sql = false
202
+ builder = @sampler.tl_builder
203
+ @sampler.expects(:notice_extra_data).with(builder, 'some sql', 1.0, :sql).never # <--- important
204
+ @sampler.notice_sql('some sql', {:config => 'a config'}, 1.0, @state)
255
205
  end
256
206
 
257
207
  def test_notice_nosql
258
- @sampler.expects(:notice_extra_data).with('a key', 1.0, :key)
208
+ builder = @sampler.tl_builder
209
+ @sampler.expects(:notice_extra_data).with(builder, 'a key', 1.0, :key)
259
210
  @sampler.notice_nosql('a key', 1.0)
260
211
  end
261
212
 
262
213
  def test_notice_nosql_statement
263
- @sampler.expects(:notice_extra_data).with('query data', 1.0, :statement)
214
+ builder = @sampler.tl_builder
215
+ @sampler.expects(:notice_extra_data).with(builder, 'query data', 1.0, :statement)
264
216
  @sampler.notice_nosql_statement('query data', 1.0)
265
217
  end
266
218
 
@@ -450,42 +402,36 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
450
402
  end
451
403
 
452
404
  def test_start_builder_default
453
- NewRelic::Agent.expects(:is_execution_traced?).returns(true)
454
- @sampler.send(:start_builder)
455
- assert(NewRelic::Agent::TransactionState.get.transaction_sample_builder \
456
- .is_a?(NewRelic::Agent::TransactionSampleBuilder),
405
+ @state.expects(:is_execution_traced?).returns(true)
406
+ @sampler.send(:start_builder, @state)
407
+ assert(@state.transaction_sample_builder.is_a?(NewRelic::Agent::TransactionSampleBuilder),
457
408
  "should set up a new builder by default")
458
409
  end
459
410
 
460
411
  def test_start_builder_disabled
461
- NewRelic::Agent::TransactionState.get.transaction_sample_builder = 'not nil.'
412
+ @state.transaction_sample_builder = 'not nil.'
462
413
  with_config(:'transaction_tracer.enabled' => false,
463
414
  :developer_mode => false) do
464
- @sampler.send(:start_builder)
465
- assert_equal(nil, NewRelic::Agent::TransactionState.get.transaction_sample_builder,
415
+ @sampler.send(:start_builder, @state)
416
+ assert_equal(nil, @state.transaction_sample_builder,
466
417
  "should clear the transaction builder when disabled")
467
418
  end
468
419
  end
469
420
 
470
421
  def test_start_builder_dont_replace_existing_builder
471
422
  fake_builder = mock('transaction sample builder')
472
- NewRelic::Agent::TransactionState.get.transaction_sample_builder = fake_builder
473
- @sampler.send(:start_builder)
474
- assert_equal(fake_builder, NewRelic::Agent::TransactionState.get.transaction_sample_builder,
423
+ @state.transaction_sample_builder = fake_builder
424
+ @sampler.send(:start_builder, @state)
425
+ assert_equal(fake_builder, @state.transaction_sample_builder,
475
426
  "should not overwrite an existing transaction sample builder")
476
- NewRelic::Agent::TransactionState.get.transaction_sample_builder = nil
427
+ @state.transaction_sample_builder = nil
477
428
  end
478
429
 
479
430
  def test_builder
480
- NewRelic::Agent::TransactionState.get.transaction_sample_builder = 'shamalamadingdong, brother.'
481
- assert_equal('shamalamadingdong, brother.', @sampler.send(:builder),
431
+ @state.transaction_sample_builder = 'shamalamadingdong, brother.'
432
+ assert_equal('shamalamadingdong, brother.', @sampler.send(:tl_builder),
482
433
  'should return the value from the thread local variable')
483
- NewRelic::Agent::TransactionState.get.transaction_sample_builder = nil
484
- end
485
-
486
- def test_clear_builder
487
- NewRelic::Agent::TransactionState.get.transaction_sample_builder = 'shamalamadingdong, brother.'
488
- assert_equal(nil, @sampler.send(:clear_builder), 'should clear the thread local variable')
434
+ @state.transaction_sample_builder = nil
489
435
  end
490
436
 
491
437
  # Tests below this line are functional tests for the sampler, not
@@ -495,19 +441,19 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
495
441
 
496
442
  def test_sample_tree
497
443
  with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
498
- @sampler.on_start_transaction(Time.now, nil, {})
499
- @sampler.notice_push_frame
444
+ @sampler.on_start_transaction(@state, Time.now, nil)
445
+ @sampler.notice_push_frame(@state)
500
446
 
501
- @sampler.notice_push_frame
502
- @sampler.notice_pop_frame "b"
447
+ @sampler.notice_push_frame(@state)
448
+ @sampler.notice_pop_frame(@state, "b")
503
449
 
504
- @sampler.notice_push_frame
505
- @sampler.notice_push_frame
506
- @sampler.notice_pop_frame "d"
507
- @sampler.notice_pop_frame "c"
450
+ @sampler.notice_push_frame(@state)
451
+ @sampler.notice_push_frame(@state)
452
+ @sampler.notice_pop_frame(@state, "d")
453
+ @sampler.notice_pop_frame(@state, "c")
508
454
 
509
- @sampler.notice_pop_frame "a"
510
- @sampler.on_finishing_transaction(@txn)
455
+ @sampler.notice_pop_frame(@state, "a")
456
+ @sampler.on_finishing_transaction(@state, @txn)
511
457
  sample = @sampler.harvest!.first
512
458
  assert_equal "ROOT{a{b,c{d}}}", sample.to_s_compact
513
459
  end
@@ -520,19 +466,19 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
520
466
  MockGCStats.mock_values = [0,0,0,1,0,0,1,0,0,0,0,0,0,0,0]
521
467
 
522
468
  with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
523
- @sampler.on_start_transaction(Time.now, nil, {})
524
- @sampler.notice_push_frame
469
+ @sampler.on_start_transaction(@state, Time.now, nil)
470
+ @sampler.notice_push_frame(@state)
525
471
 
526
- @sampler.notice_push_frame
527
- @sampler.notice_pop_frame "b"
472
+ @sampler.notice_push_frame(@state)
473
+ @sampler.notice_pop_frame(@state, "b")
528
474
 
529
- @sampler.notice_push_frame
530
- @sampler.notice_push_frame
531
- @sampler.notice_pop_frame "d"
532
- @sampler.notice_pop_frame "c"
475
+ @sampler.notice_push_frame(@state)
476
+ @sampler.notice_push_frame(@state)
477
+ @sampler.notice_pop_frame(@state, "d")
478
+ @sampler.notice_pop_frame(@state, "c")
533
479
 
534
- @sampler.notice_pop_frame "a"
535
- @sampler.on_finishing_transaction(@txn)
480
+ @sampler.notice_pop_frame(@state, "a")
481
+ @sampler.on_finishing_transaction(@state, @txn)
536
482
 
537
483
  sample = @sampler.harvest!.first
538
484
  assert_equal "ROOT{a{b,c{d}}}", sample.to_s_compact
@@ -589,36 +535,37 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
589
535
  threads = []
590
536
 
591
537
  5.times do
592
- t = Thread.new(@sampler) do |the_sampler|
593
- @sampler = the_sampler
538
+ threads << Thread.new do
594
539
  10.times do
595
- run_sample_trace { sleep 0.0001 }
540
+ # Important that this uses the actual thread-local, not the shared
541
+ # @state variable used in other non-threaded tests
542
+ run_sample_trace(Time.now.to_f, nil, NewRelic::Agent::TransactionState.tl_get) do
543
+ sleep 0.0001
544
+ end
596
545
  end
597
546
  end
598
-
599
- threads << t
600
547
  end
601
548
  threads.each {|t| t.join }
602
549
  end
603
550
 
604
551
  def test_sample_with_parallel_paths
605
552
  with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
606
- @sampler.on_start_transaction(Time.now, nil, {})
607
- @sampler.notice_push_frame
553
+ @sampler.on_start_transaction(@state, Time.now, nil)
554
+ @sampler.notice_push_frame(@state)
608
555
 
609
- assert_equal 1, @sampler.builder.scope_depth
556
+ assert_equal 1, @sampler.tl_builder.scope_depth
610
557
 
611
- @sampler.notice_pop_frame "a"
612
- @sampler.on_finishing_transaction(@txn)
558
+ @sampler.notice_pop_frame(@state, "a")
559
+ @sampler.on_finishing_transaction(@state, @txn)
613
560
 
614
- assert_nil @sampler.builder
561
+ assert_nil @sampler.tl_builder
615
562
 
616
- @sampler.on_start_transaction(Time.now, nil, {})
617
- @sampler.notice_push_frame
618
- @sampler.notice_pop_frame "a"
619
- @sampler.on_finishing_transaction(@txn)
563
+ @sampler.on_start_transaction(@state, Time.now, nil)
564
+ @sampler.notice_push_frame(@state)
565
+ @sampler.notice_pop_frame(@state, "a")
566
+ @sampler.on_finishing_transaction(@state, @txn)
620
567
 
621
- assert_nil @sampler.builder
568
+ assert_nil @sampler.tl_builder
622
569
 
623
570
  assert_equal "ROOT{a}", @sampler.last_sample.to_s_compact
624
571
  end
@@ -626,13 +573,13 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
626
573
 
627
574
  def test_double_traced_method_stack_empty
628
575
  with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
629
- @sampler.on_start_transaction(Time.now, nil, {})
630
- @sampler.notice_push_frame
631
- @sampler.notice_pop_frame "a"
632
- @sampler.on_finishing_transaction(@txn)
633
- @sampler.on_finishing_transaction(@txn)
634
- @sampler.on_finishing_transaction(@txn)
635
- @sampler.on_finishing_transaction(@txn)
576
+ @sampler.on_start_transaction(@state, Time.now, nil)
577
+ @sampler.notice_push_frame(@state)
578
+ @sampler.notice_pop_frame(@state, "a")
579
+ @sampler.on_finishing_transaction(@state, @txn)
580
+ @sampler.on_finishing_transaction(@state, @txn)
581
+ @sampler.on_finishing_transaction(@state, @txn)
582
+ @sampler.on_finishing_transaction(@state, @txn)
636
583
 
637
584
  refute_nil @sampler.harvest![0]
638
585
  end
@@ -640,22 +587,22 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
640
587
 
641
588
 
642
589
  def test_record_sql_off
643
- @sampler.on_start_transaction Time.now.to_f
590
+ @sampler.on_start_transaction(@state, Time.now.to_f)
644
591
 
645
- NewRelic::Agent::TransactionState.get.record_sql = false
592
+ @state.record_sql = false
646
593
 
647
- @sampler.notice_sql("test", {}, 0)
594
+ @sampler.notice_sql("test", {}, 0, @state)
648
595
 
649
- segment = @sampler.send(:builder).current_segment
596
+ segment = @sampler.send(:tl_builder).current_segment
650
597
 
651
598
  assert_nil segment[:sql]
652
599
  end
653
600
 
654
601
  def test_stack_trace_sql
655
602
  with_config(:'transaction_tracer.stack_trace_threshold' => 0) do
656
- @sampler.on_start_transaction Time.now.to_f
657
- @sampler.notice_sql("test", {}, 1)
658
- segment = @sampler.send(:builder).current_segment
603
+ @sampler.on_start_transaction(@state, Time.now.to_f)
604
+ @sampler.notice_sql("test", {}, 1, @state)
605
+ segment = @sampler.send(:tl_builder).current_segment
659
606
 
660
607
  assert segment[:sql]
661
608
  assert segment[:backtrace]
@@ -665,19 +612,19 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
665
612
  def test_stack_trace_scope
666
613
  with_config(:'transaction_tracer.stack_trace_threshold' => 0) do
667
614
  t = Time.now
668
- @sampler.on_start_transaction t.to_f
669
- @sampler.notice_push_frame((t+1).to_f)
615
+ @sampler.on_start_transaction(@state, t.to_f)
616
+ @sampler.notice_push_frame(@state, (t+1).to_f)
670
617
 
671
- segment = @sampler.send(:builder).current_segment
618
+ segment = @sampler.send(:tl_builder).current_segment
672
619
  assert segment[:backtrace]
673
620
  end
674
621
  end
675
622
 
676
623
  def test_nil_stacktrace
677
624
  with_config(:'transaction_tracer.stack_trace_threshold' => 2) do
678
- @sampler.on_start_transaction Time.now.to_f
679
- @sampler.notice_sql("test", {}, 1)
680
- segment = @sampler.send(:builder).current_segment
625
+ @sampler.on_start_transaction(@state, Time.now.to_f)
626
+ @sampler.notice_sql("test", {}, 1, @state)
627
+ segment = @sampler.send(:tl_builder).current_segment
681
628
 
682
629
  assert segment[:sql]
683
630
  assert_nil segment[:backtrace]
@@ -685,17 +632,17 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
685
632
  end
686
633
 
687
634
  def test_big_sql
688
- @sampler.on_start_transaction Time.now.to_f
635
+ @sampler.on_start_transaction(@state, Time.now.to_f)
689
636
 
690
637
  sql = "SADJKHASDHASD KAJSDH ASKDH ASKDHASDK JASHD KASJDH ASKDJHSAKDJHAS DKJHSADKJSAH DKJASHD SAKJDH SAKDJHS"
691
638
 
692
639
  len = 0
693
640
  while len <= 16384
694
- @sampler.notice_sql(sql, {}, 0)
641
+ @sampler.notice_sql(sql, {}, 0, @state)
695
642
  len += sql.length
696
643
  end
697
644
 
698
- segment = @sampler.send(:builder).current_segment
645
+ segment = @sampler.send(:tl_builder).current_segment
699
646
 
700
647
  sql = segment[:sql]
701
648
 
@@ -703,26 +650,27 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
703
650
  end
704
651
 
705
652
  def test_segment_obfuscated
706
- @sampler.on_start_transaction Time.now.to_f
707
- @sampler.notice_push_frame
653
+ @sampler.on_start_transaction(@state, Time.now.to_f)
654
+ @sampler.notice_push_frame(@state)
708
655
 
709
656
  orig_sql = "SELECT * from Jim where id=66"
710
657
 
711
- @sampler.notice_sql(orig_sql, {}, 0)
658
+ @sampler.notice_sql(orig_sql, {}, 0, @state)
712
659
 
713
- segment = @sampler.send(:builder).current_segment
660
+ segment = @sampler.send(:tl_builder).current_segment
714
661
 
715
662
  assert_equal orig_sql, segment[:sql]
716
663
  assert_equal "SELECT * from Jim where id=?", segment.obfuscated_sql
717
- @sampler.notice_pop_frame "foo"
664
+ @sampler.notice_pop_frame(@state, "foo")
718
665
  end
719
666
 
720
667
  def test_param_capture
721
668
  [true, false].each do |capture|
722
669
  with_config(:capture_params => capture) do
723
670
  tt = with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
724
- @sampler.on_start_transaction(Time.now, nil, :param => 'hi')
725
- @sampler.on_finishing_transaction(@txn)
671
+ @sampler.on_start_transaction(@state, Time.now, nil)
672
+ @txn.filtered_params[:param] = 'hi'
673
+ @sampler.on_finishing_transaction(@state, @txn)
726
674
  @sampler.harvest![0]
727
675
  end
728
676
 
@@ -734,12 +682,12 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
734
682
  def test_should_not_collect_segments_beyond_limit
735
683
  with_config(:'transaction_tracer.limit_segments' => 3) do
736
684
  run_sample_trace do
737
- @sampler.notice_push_frame
738
- @sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'challah'", {}, 0)
739
- @sampler.notice_push_frame
740
- @sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'semolina'", {}, 0)
741
- @sampler.notice_pop_frame "a11"
742
- @sampler.notice_pop_frame "a1"
685
+ @sampler.notice_push_frame(@state)
686
+ @sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'challah'", {}, 0, @state)
687
+ @sampler.notice_push_frame(@state)
688
+ @sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'semolina'", {}, 0, @state)
689
+ @sampler.notice_pop_frame(@state, "a11")
690
+ @sampler.notice_pop_frame(@state, "a1")
743
691
  end
744
692
  assert_equal 3, @sampler.last_sample.count_segments
745
693
 
@@ -751,17 +699,17 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
751
699
  end
752
700
 
753
701
  def test_renaming_current_segment_midflight
754
- @sampler.start_builder
755
- segment = @sampler.notice_push_frame
702
+ @sampler.start_builder(@state)
703
+ segment = @sampler.notice_push_frame(@state)
756
704
  segment.metric_name = 'External/www.google.com/Net::HTTP/GET'
757
- @sampler.notice_pop_frame( 'External/www.google.com/Net::HTTP/GET' )
705
+ @sampler.notice_pop_frame(@state, 'External/www.google.com/Net::HTTP/GET')
758
706
  end
759
707
 
760
708
  def test_adding_segment_parameters
761
- @sampler.start_builder
762
- @sampler.notice_push_frame
763
- @sampler.add_segment_parameters( :transaction_guid => '97612F92E6194080' )
764
- assert_equal '97612F92E6194080', @sampler.builder.current_segment[:transaction_guid]
709
+ @sampler.start_builder(@state)
710
+ @sampler.notice_push_frame(@state)
711
+ @sampler.add_segment_parameters(:transaction_guid => '97612F92E6194080')
712
+ assert_equal '97612F92E6194080', @sampler.tl_builder.current_segment[:transaction_guid]
765
713
  end
766
714
 
767
715
  def test_large_transaction_trace_harvest
@@ -840,7 +788,7 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
840
788
  include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
841
789
  def run(n)
842
790
  n.times do
843
- perform_action_with_newrelic_trace("smile") do
791
+ perform_action_with_newrelic_trace(:name => 'smile') do
844
792
  end
845
793
  end
846
794
  end
@@ -902,27 +850,27 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
902
850
  end
903
851
 
904
852
  def run_long_sample_trace(n)
905
- @sampler.on_start_transaction(Time.now, nil, {})
853
+ @sampler.on_start_transaction(@state, Time.now, nil)
906
854
  n.times do |i|
907
- @sampler.notice_push_frame
855
+ @sampler.notice_push_frame(@state)
908
856
  yield if block_given?
909
- @sampler.notice_pop_frame "node#{i}"
857
+ @sampler.notice_pop_frame(@state, "node#{i}")
910
858
  end
911
- @sampler.on_finishing_transaction(@txn, Time.now.to_f)
859
+ @sampler.on_finishing_transaction(@state, @txn, Time.now.to_f)
912
860
  end
913
861
 
914
- def run_sample_trace(start = Time.now.to_f, stop = nil)
915
- @sampler.on_start_transaction(start, nil, {})
916
- @sampler.notice_push_frame
917
- @sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'wheat'", {}, 0)
918
- @sampler.notice_push_frame
919
- @sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'white'", {}, 0)
862
+ def run_sample_trace(start = Time.now.to_f, stop = nil, state = @state)
863
+ @sampler.on_start_transaction(state, start, nil)
864
+ @sampler.notice_push_frame(state)
865
+ @sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'wheat'", {}, 0, state)
866
+ @sampler.notice_push_frame(state)
867
+ @sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'white'", {}, 0, state)
920
868
  yield if block_given?
921
- @sampler.notice_pop_frame "ab"
922
- @sampler.notice_push_frame
923
- @sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'french'", {}, 0)
924
- @sampler.notice_pop_frame "ac"
925
- @sampler.notice_pop_frame "a"
926
- @sampler.on_finishing_transaction(@txn, (stop || Time.now.to_f))
869
+ @sampler.notice_pop_frame(state, "ab")
870
+ @sampler.notice_push_frame(state)
871
+ @sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'french'", {}, 0, state)
872
+ @sampler.notice_pop_frame(state, "ac")
873
+ @sampler.notice_pop_frame(state, "a")
874
+ @sampler.on_finishing_transaction(state, @txn, (stop || Time.now.to_f))
927
875
  end
928
876
  end