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
@@ -28,7 +28,9 @@ class NewRelic::Agent::Instrumentation::SinatraTest < Minitest::Test
28
28
  expected_headers = {:fake => :header}
29
29
  @app.request = mock('request', :env => expected_headers)
30
30
 
31
- assert_equal @app.newrelic_request_headers, expected_headers
31
+ state = NewRelic::Agent::TransactionState.tl_get
32
+
33
+ assert_equal(@app.newrelic_request_headers(state), expected_headers)
32
34
  end
33
35
 
34
36
  def test_process_route_with_bad_arguments
@@ -18,19 +18,19 @@ class NewRelic::Agent::JavascriptInstrumentorTest < Minitest::Test
18
18
  :license_key => "\0", # no-op obfuscation key
19
19
  :'rum.enabled' => true
20
20
  }
21
- NewRelic::Agent.config.apply_config(@config)
21
+ NewRelic::Agent.config.add_config_for_testing(@config)
22
22
 
23
23
  events = stub(:subscribe => nil)
24
24
  @instrumentor = NewRelic::Agent::JavascriptInstrumentor.new(events)
25
25
 
26
26
  # By default we expect our transaction to have a start time
27
27
  # All sorts of basics don't output without this setup initially
28
- NewRelic::Agent::TransactionState.reset
28
+ NewRelic::Agent::TransactionState.tl_get.reset
29
29
  end
30
30
 
31
31
  def teardown
32
- NewRelic::Agent::TransactionState.clear
33
- NewRelic::Agent.config.remove_config(@config)
32
+ NewRelic::Agent::TransactionState.tl_clear_for_testing
33
+ NewRelic::Agent.config.reset_to_defaults
34
34
  end
35
35
 
36
36
  def test_js_errors_beta_default_gets_default_loader
@@ -53,27 +53,6 @@ class NewRelic::Agent::JavascriptInstrumentorTest < Minitest::Test
53
53
  assert NewRelic::Agent.config[:'browser_monitoring.auto_instrument']
54
54
  end
55
55
 
56
- def test_start_time_reset_each_request_when_auto_instrument_is_disabled
57
- controller = Object.new
58
- def controller.perform_action_without_newrelic_trace(method, options={});
59
- # noop; instrument me
60
- end
61
- def controller.newrelic_metric_path; "foo"; end
62
- controller.extend ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
63
-
64
- with_config(:'browser_monitoring.auto_instrument' => false) do
65
- controller.perform_action_with_newrelic_trace(:index)
66
- first_request_start_time = instrumentor.current_transaction.start_time
67
-
68
- controller.perform_action_with_newrelic_trace(:index)
69
- second_request_start_time = instrumentor.current_transaction.start_time
70
-
71
- # assert that these aren't the same time object
72
- # the start time should be reinitialized each request to the controller
73
- assert !(first_request_start_time.equal? second_request_start_time)
74
- end
75
- end
76
-
77
56
  def test_browser_timing_header_outside_transaction
78
57
  assert_equal "", instrumentor.browser_timing_header
79
58
  end
@@ -127,8 +106,8 @@ class NewRelic::Agent::JavascriptInstrumentorTest < Minitest::Test
127
106
  end
128
107
 
129
108
  def test_browser_timing_header_with_ignored_enduser
130
- in_transaction do
131
- NewRelic::Agent::TransactionState.get.request_ignore_enduser = true
109
+ in_transaction do |txn|
110
+ txn.ignore_enduser!
132
111
  assert_equal "", instrumentor.browser_timing_header
133
112
  end
134
113
  end
@@ -144,12 +123,15 @@ class NewRelic::Agent::JavascriptInstrumentorTest < Minitest::Test
144
123
 
145
124
  def test_browser_timing_header_safe_when_insert_js_fails
146
125
  in_transaction do
147
- NewRelic::Agent.stubs(:config).raises("Hahahaha")
148
- assert_equal "", instrumentor.browser_timing_header
126
+ begin
127
+ NewRelic::Agent.stubs(:config).raises("Hahahaha")
128
+ assert_equal "", instrumentor.browser_timing_header
129
+ ensure
130
+ # stopping the transaction touches config, so we need to ensure we
131
+ # clean up after ourselves here.
132
+ NewRelic::Agent.unstub(:config)
133
+ end
149
134
  end
150
- ensure
151
- # Teardown touches config, so make sure we're clean before we bail here
152
- NewRelic::Agent.unstub(:config)
153
135
  end
154
136
 
155
137
  def test_browser_timing_header_safe_when_loader_generation_fails
@@ -172,15 +154,15 @@ class NewRelic::Agent::JavascriptInstrumentorTest < Minitest::Test
172
154
  with_config(CAPTURE_ATTRIBUTES => true) do
173
155
  NewRelic::Agent.set_user_attributes(:user => "user")
174
156
 
175
- txn = NewRelic::Agent::Transaction.current
157
+ txn = NewRelic::Agent::Transaction.tl_current
176
158
  txn.stubs(:queue_time).returns(0)
177
159
  txn.stubs(:start_time).returns(Time.now - 10)
178
160
  txn.stubs(:guid).returns('ABC')
179
161
 
180
- state = NewRelic::Agent::TransactionState.get
162
+ state = NewRelic::Agent::TransactionState.tl_get
181
163
  state.request_token = '0123456789ABCDEF'
182
164
 
183
- data = instrumentor.data_for_js_agent
165
+ data = instrumentor.data_for_js_agent(state)
184
166
  expected = {
185
167
  "beacon" => "beacon",
186
168
  "errorBeacon" => "",
@@ -197,7 +179,7 @@ class NewRelic::Agent::JavascriptInstrumentorTest < Minitest::Test
197
179
 
198
180
  assert_equal(expected, data)
199
181
 
200
- js = instrumentor.browser_timing_config
182
+ js = instrumentor.browser_timing_config(state)
201
183
  expected.each do |key, value|
202
184
  assert_match(/"#{key.to_s}":#{formatted_for_matching(value)}/, js)
203
185
  end
@@ -206,20 +188,23 @@ class NewRelic::Agent::JavascriptInstrumentorTest < Minitest::Test
206
188
  end
207
189
 
208
190
  def test_ssl_for_http_not_included_by_default
209
- data = instrumentor.data_for_js_agent
191
+ state = NewRelic::Agent::TransactionState.tl_get
192
+ data = instrumentor.data_for_js_agent(state)
210
193
  assert_not_includes data, "sslForHttp"
211
194
  end
212
195
 
213
196
  def test_ssl_for_http_enabled
214
197
  with_config(:'browser_monitoring.ssl_for_http' => true) do
215
- data = instrumentor.data_for_js_agent
198
+ state = NewRelic::Agent::TransactionState.tl_get
199
+ data = instrumentor.data_for_js_agent(state)
216
200
  assert data["sslForHttp"]
217
201
  end
218
202
  end
219
203
 
220
204
  def test_ssl_for_http_disabled
221
205
  with_config(:'browser_monitoring.ssl_for_http' => false) do
222
- data = instrumentor.data_for_js_agent
206
+ state = NewRelic::Agent::TransactionState.tl_get
207
+ data = instrumentor.data_for_js_agent(state)
223
208
  assert_false data["sslForHttp"]
224
209
  end
225
210
  end
@@ -305,12 +290,14 @@ class NewRelic::Agent::JavascriptInstrumentorTest < Minitest::Test
305
290
  end
306
291
 
307
292
  def assert_user_attributes_are(expected)
308
- data = instrumentor.data_for_js_agent
293
+ state = NewRelic::Agent::TransactionState.tl_get
294
+ data = instrumentor.data_for_js_agent(state)
309
295
  assert_equal pack(expected), data["userAttributes"]
310
296
  end
311
297
 
312
298
  def assert_user_attributes_missing
313
- data = instrumentor.data_for_js_agent
299
+ state = NewRelic::Agent::TransactionState.tl_get
300
+ data = instrumentor.data_for_js_agent(state)
314
301
  assert_not_includes data, "userAttributes"
315
302
  end
316
303
 
@@ -41,6 +41,20 @@ class MemoryLoggerTest < Minitest::Test
41
41
  @logger.dump(real_logger)
42
42
  end
43
43
 
44
+ def test_proxies_message_blocks
45
+ called = false
46
+ @logger.info do
47
+ called = true
48
+ 'a'
49
+ end
50
+
51
+ real_logger = stub
52
+ real_logger.expects(:info).yields()
53
+
54
+ @logger.dump(real_logger)
55
+ assert called
56
+ end
57
+
44
58
  def test_proxies_through_calls_to_log_exception
45
59
  e = Exception.new
46
60
  @logger.log_exception(:fatal, e, :error)
@@ -24,7 +24,7 @@ class MethodInterrobangTest < Minitest::Test
24
24
  assert_equal "say what?", interrogate?
25
25
  end
26
26
 
27
- def test_aliase_method_ending_in_exclamation_makr
27
+ def test_alias_method_ending_in_exclamation_mark
28
28
  assert_respond_to self, :mutate!
29
29
  assert_equal "oh yeah!", mutate!
30
30
  end
@@ -22,7 +22,6 @@ module NewRelic
22
22
 
23
23
  def test_validate_options_defaults
24
24
  self.expects(:check_for_illegal_keys!)
25
- self.expects(:set_deduct_call_time_based_on_metric).with(DEFAULT_SETTINGS)
26
25
  self.expects(:check_for_push_scope_and_metric)
27
26
  validate_options(:applejack, {})
28
27
  end
@@ -54,34 +53,6 @@ module NewRelic
54
53
  assert !self.class.newrelic_method_exists?('test_method')
55
54
  end
56
55
 
57
- def test_set_deduct_call_time_based_on_metric_positive
58
- opts = {:metric => true}
59
- val = set_deduct_call_time_based_on_metric(opts)
60
- assert val.is_a?(Hash)
61
- assert val[:deduct_call_time_from_parent]
62
- end
63
-
64
- def test_set_deduct_call_time_based_on_metric_negative
65
- opts = {:metric => false}
66
- val = set_deduct_call_time_based_on_metric(opts)
67
- assert val.is_a?(Hash)
68
- assert !val[:deduct_call_time_from_parent]
69
- end
70
-
71
- def test_set_deduct_call_time_based_on_metric_non_nil
72
- opts = {:deduct_call_time_from_parent => true, :metric => false}
73
- val = set_deduct_call_time_based_on_metric(opts)
74
- assert val.is_a?(Hash)
75
- assert val[:deduct_call_time_from_parent]
76
- end
77
-
78
- def test_set_deduct_call_time_based_on_metric_opposite
79
- opts = {:deduct_call_time_from_parent => false, :metric => true}
80
- val = set_deduct_call_time_based_on_metric(opts)
81
- assert val.is_a?(Hash)
82
- assert !val[:deduct_call_time_from_parent]
83
- end
84
-
85
56
  def test_check_for_illegal_keys_positive
86
57
  assert_raises(RuntimeError) do
87
58
  check_for_illegal_keys!(:twilight_sparkle, {:unknown_key => nil})
@@ -118,7 +89,7 @@ module NewRelic
118
89
  def test_assemble_code_header_unforced
119
90
  self.expects(:_untraced_method_name).returns("method_name_without_tracing")
120
91
  opts = {:force => false, :code_header => 'CODE HEADER'}
121
- assert_equal "return method_name_without_tracing(*args, &block) unless NewRelic::Agent.is_execution_traced?\nCODE HEADER", assemble_code_header('test_method', 'Custom/Test/test_method', opts)
92
+ assert_equal "return method_name_without_tracing(*args, &block) unless NewRelic::Agent.tl_is_execution_traced?\nCODE HEADER", assemble_code_header('test_method', 'Custom/Test/test_method', opts)
122
93
  end
123
94
 
124
95
  def test_check_for_push_scope_and_metric_positive
@@ -136,22 +136,6 @@ class NewRelic::Agent::MethodTracer::TraceExecutionScopedTest < Minitest::Test
136
136
  )
137
137
  end
138
138
 
139
- def test_metric_recording_with_scoped_metric_only_option
140
- options = { :scoped_metric_only => true }
141
-
142
- in_transaction('outer') do
143
- trace_execution_scoped(['foo', 'bar'], options) do
144
- # erm
145
- end
146
- end
147
-
148
- expected_values = { :call_count => 1 }
149
- assert_metrics_recorded_exclusive(
150
- 'outer' => expected_values,
151
- ['foo', 'outer'] => expected_values
152
- )
153
- end
154
-
155
139
  def test_set_if_nil
156
140
  h = {}
157
141
  set_if_nil(h, :foo)
@@ -191,10 +175,11 @@ class NewRelic::Agent::MethodTracer::TraceExecutionScopedTest < Minitest::Test
191
175
  end
192
176
 
193
177
  def test_trace_execution_scoped_header
194
- options = {:force => false, :deduct_call_time_from_parent => false}
195
- self.expects(:log_errors).with('trace_execution_scoped header').yields
196
- NewRelic::Agent::TracedMethodStack.expects(:push_frame).with(:method_tracer, 1.0, false)
197
- trace_execution_scoped_header(options, 1.0)
178
+ state = NewRelic::Agent::TransactionState.tl_get
179
+ stack = state.traced_method_stack
180
+ self.expects(:log_errors).with(:trace_execution_scoped_header).yields
181
+ stack.expects(:push_frame).with(state, :method_tracer, 1.0)
182
+ trace_execution_scoped_header(state, 1.0)
198
183
  end
199
184
 
200
185
  def test_trace_execution_scoped_calculates_exclusive_time
@@ -236,7 +221,6 @@ class NewRelic::Agent::MethodTracer::TraceExecutionScopedTest < Minitest::Test
236
221
  end
237
222
 
238
223
  def test_trace_execution_scoped_disabled
239
- self.expects(:traced?).returns(false)
240
224
  # make sure the method doesn't beyond the abort
241
225
  self.expects(:set_if_nil).never
242
226
  ran = false
@@ -62,7 +62,7 @@ class NewRelic::Agent::MethodTracerTest < Minitest::Test
62
62
  attr_reader :stats_engine
63
63
 
64
64
  def setup
65
- NewRelic::Agent::TransactionState.clear
65
+ NewRelic::Agent::TransactionState.tl_clear_for_testing
66
66
 
67
67
  NewRelic::Agent.manual_start
68
68
  @stats_engine = NewRelic::Agent.instance.stats_engine
@@ -93,7 +93,8 @@ class NewRelic::Agent::MethodTracerTest < Minitest::Test
93
93
  end
94
94
 
95
95
  def test_record_metrics_does_not_raise_outside_transaction
96
- NewRelic::Agent::MethodTracer::TraceExecutionScoped.record_metrics('a', ['b'], 12, 10, :metric => true)
96
+ state = NewRelic::Agent::TransactionState.tl_get
97
+ NewRelic::Agent::MethodTracer::TraceExecutionScoped.record_metrics(state, 'a', ['b'], 12, 10, :metric => true)
97
98
 
98
99
  expected = { :call_count => 1, :total_call_time => 12, :total_exclusive_time => 10 }
99
100
  assert_metrics_recorded('a' => expected, 'b' => expected)
@@ -179,8 +180,8 @@ class NewRelic::Agent::MethodTracerTest < Minitest::Test
179
180
 
180
181
  stats = @stats_engine.get_stats("Custom/#{self.class.name}/simple_method")
181
182
  assert stats.call_count == 1
182
-
183
183
  end
184
+
184
185
  def test_add_method_tracer__reentry
185
186
  self.class.add_method_tracer :simple_method
186
187
  self.class.add_method_tracer :simple_method
@@ -352,7 +353,7 @@ class NewRelic::Agent::MethodTracerTest < Minitest::Test
352
353
  begin
353
354
  metric = "hey"
354
355
  self.class.trace_execution_scoped(metric) do
355
- throw StandardError.new
356
+ raise StandardError.new
356
357
  end
357
358
 
358
359
  assert false # should never get here
@@ -11,10 +11,10 @@ class NewRelic::Agent::MockScopeListener
11
11
  @scopes = []
12
12
  end
13
13
 
14
- def notice_push_frame(time)
14
+ def notice_push_frame(state, time)
15
15
  end
16
16
 
17
- def notice_pop_frame(scope, time)
17
+ def notice_pop_frame(state, scope, time)
18
18
  @scopes << scope
19
19
  end
20
20
 
@@ -12,7 +12,7 @@ class NewRelic::Agent::ObfuscatorTest < Minitest::Test
12
12
 
13
13
  def setup
14
14
  @config = { :license_key => OBFUSCATION_KEY }
15
- NewRelic::Agent.config.apply_config(@config)
15
+ NewRelic::Agent.config.add_config_for_testing(@config)
16
16
  end
17
17
 
18
18
  def teardown
@@ -12,10 +12,10 @@ class NewRelic::Agent::PipeChannelManagerTest < Minitest::Test
12
12
  def setup
13
13
  @test_config = { :developer_mode => true }
14
14
  NewRelic::Agent.agent.drop_buffered_data
15
- NewRelic::Agent.config.apply_config(@test_config)
15
+ NewRelic::Agent.config.add_config_for_testing(@test_config)
16
16
  NewRelic::Agent::PipeChannelManager.listener.close_all_pipes
17
17
  NewRelic::Agent.manual_start
18
- NewRelic::Agent::TransactionState.clear
18
+ NewRelic::Agent::TransactionState.tl_clear_for_testing
19
19
  end
20
20
 
21
21
  def teardown
@@ -161,6 +161,17 @@ class NewRelic::Agent::PipeChannelManagerTest < Minitest::Test
161
161
  listener.stop
162
162
  end
163
163
 
164
+ def test_manager_does_not_crash_when_given_unmarshallable_junk
165
+ listener = start_listener_with_pipe(671)
166
+ expects_logging(:error, any_parameters)
167
+
168
+ pid = Process.fork do
169
+ listener.pipes[671].write("\x00")
170
+ end
171
+ Process.wait(pid)
172
+ listener.stop
173
+ end
174
+
164
175
  def pipe_finished?(id)
165
176
  (!NewRelic::Agent::PipeChannelManager.channels[id] ||
166
177
  NewRelic::Agent::PipeChannelManager.channels[id].closed?)
@@ -172,9 +183,10 @@ class NewRelic::Agent::PipeChannelManagerTest < Minitest::Test
172
183
  end
173
184
 
174
185
  def create_sql_sample(sampler)
175
- sampler.on_start_transaction(Time.now)
176
- sampler.notice_sql("SELECT * FROM table", "ActiveRecord/Widgets/find", nil, 100)
177
- sampler.on_finishing_transaction('noodles', Time.now)
186
+ state = NewRelic::Agent::TransactionState.tl_get
187
+ sampler.on_start_transaction(state, Time.now)
188
+ sampler.notice_sql("SELECT * FROM table", "ActiveRecord/Widgets/find", nil, 100, state)
189
+ sampler.on_finishing_transaction(state, 'noodles', Time.now)
178
190
  end
179
191
  end
180
192
 
@@ -68,11 +68,11 @@ class NewRelic::Agent::RequestSamplerTest < Minitest::Test
68
68
 
69
69
  def test_custom_parameters_in_event_cant_override_reserved_attributes
70
70
  with_sampler_config do
71
- metrics = NewRelic::Agent::StatsHash.new()
72
- metrics.record(NewRelic::MetricSpec.new('HttpDispatcher'), 0.01)
71
+ metrics = NewRelic::Agent::TransactionMetrics.new()
72
+ metrics.record_unscoped('HttpDispatcher', 0.01)
73
73
 
74
74
  generate_request('whatever',
75
- :metrics => metrics,
75
+ :metrics => metrics,
76
76
  :custom_params => {'type' => 'giraffe', 'duration' => 'hippo'}
77
77
  )
78
78
  txn_event = single_sample[EVENT_DATA_INDEX]
@@ -86,15 +86,15 @@ class NewRelic::Agent::RequestSamplerTest < Minitest::Test
86
86
  end
87
87
 
88
88
  def test_samples_on_transaction_finished_event_includes_expected_web_metrics
89
- stats_hash = NewRelic::Agent::StatsHash.new
90
- stats_hash.record(NewRelic::MetricSpec.new('WebFrontend/QueueTime'), 13)
91
- stats_hash.record(NewRelic::MetricSpec.new('External/allWeb'), 14)
92
- stats_hash.record(NewRelic::MetricSpec.new('Datastore/all'), 15)
93
- stats_hash.record(NewRelic::MetricSpec.new("GC/Transaction/all"), 16)
94
- stats_hash.record(NewRelic::MetricSpec.new('Memcache/allWeb'), 17)
89
+ txn_metrics = NewRelic::Agent::TransactionMetrics.new
90
+ txn_metrics.record_unscoped('WebFrontend/QueueTime', 13)
91
+ txn_metrics.record_unscoped('External/allWeb', 14)
92
+ txn_metrics.record_unscoped('Datastore/all', 15)
93
+ txn_metrics.record_unscoped("GC/Transaction/all", 16)
94
+ txn_metrics.record_unscoped('Memcache/allWeb', 17)
95
95
 
96
96
  with_sampler_config do
97
- generate_request('name', :metrics => stats_hash)
97
+ generate_request('name', :metrics => txn_metrics)
98
98
  event_data = single_sample[EVENT_DATA_INDEX]
99
99
  assert_equal 13, event_data["queueDuration"]
100
100
  assert_equal 14, event_data["externalDuration"]
@@ -108,14 +108,14 @@ class NewRelic::Agent::RequestSamplerTest < Minitest::Test
108
108
  end
109
109
 
110
110
  def test_samples_on_transaction_finished_includes_expected_background_metrics
111
- stats_hash = NewRelic::Agent::StatsHash.new
112
- stats_hash.record(NewRelic::MetricSpec.new('External/allOther'), 12)
113
- stats_hash.record(NewRelic::MetricSpec.new('Datastore/all'), 13)
114
- stats_hash.record(NewRelic::MetricSpec.new("GC/Transaction/all"), 14)
115
- stats_hash.record(NewRelic::MetricSpec.new('Memcache/allOther'), 15)
111
+ txn_metrics = NewRelic::Agent::TransactionMetrics.new
112
+ txn_metrics.record_unscoped('External/allOther', 12)
113
+ txn_metrics.record_unscoped('Datastore/all', 13)
114
+ txn_metrics.record_unscoped("GC/Transaction/all", 14)
115
+ txn_metrics.record_unscoped('Memcache/allOther', 15)
116
116
 
117
117
  with_sampler_config do
118
- generate_request('name', :metrics => stats_hash)
118
+ generate_request('name', :metrics => txn_metrics)
119
119
 
120
120
  event_data = single_sample[EVENT_DATA_INDEX]
121
121
  assert_equal 12, event_data["externalDuration"]