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
@@ -26,9 +26,11 @@ module NewRelic
26
26
  end
27
27
  end
28
28
 
29
- def process_action(*args)
29
+ def process_action(*args) #THREAD_LOCAL_ACCESS
30
30
  # skip instrumentation if we are in an ignored action
31
31
  if _is_filtered?('do_not_trace')
32
+ txn = NewRelic::Agent::Transaction.tl_current
33
+ txn.ignore! if txn
32
34
  NewRelic::Agent.disable_all_tracing do
33
35
  return super
34
36
  end
@@ -0,0 +1,39 @@
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 'new_relic/agent/instrumentation/middleware_proxy'
6
+
7
+ DependencyDetection.defer do
8
+ named :rails_middleware
9
+
10
+ depends_on do
11
+ defined?(::Rails) && ::Rails::VERSION::MAJOR.to_i >= 3
12
+ end
13
+
14
+ depends_on do
15
+ !::NewRelic::Agent.config[:disable_middleware_instrumentation]
16
+ end
17
+
18
+ executes do
19
+ ::NewRelic::Agent.logger.info("Installing Rails 3+ middleware instrumentation")
20
+ module ActionDispatch
21
+ class MiddlewareStack
22
+ class Middleware
23
+ def build_with_new_relic(app)
24
+ # MiddlewareProxy.wrap guards against double-wrapping here.
25
+ # We need to instrument the innermost app (usually a RouteSet),
26
+ # which will never itself be the return value from #build, but will
27
+ # instead be the initial value of the app argument.
28
+ wrapped_app = ::NewRelic::Agent::Instrumentation::MiddlewareProxy.wrap(app)
29
+ result = build_without_new_relic(wrapped_app)
30
+ ::NewRelic::Agent::Instrumentation::MiddlewareProxy.wrap(result)
31
+ end
32
+
33
+ alias_method :build_without_new_relic, :build
34
+ alias_method :build, :build_with_new_relic
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -11,14 +11,14 @@ DependencyDetection.defer do
11
11
 
12
12
  executes do
13
13
  NewRelic::Agent.instance.events.subscribe(:start_transaction) do
14
- if NewRelic::Agent.config[:'profiling.enabled']
14
+ if NewRelic::Rack::DeveloperMode.profiling_enabled?
15
15
  ::RubyProf.start
16
16
  end
17
17
  end
18
18
 
19
19
  NewRelic::Agent.instance.events.subscribe(:transaction_finished) do
20
- if NewRelic::Agent.config[:'profiling.enabled']
21
- trace = NewRelic::Agent::TransactionState.get.most_recent_transaction.transaction_trace
20
+ if NewRelic::Rack::DeveloperMode.profiling_enabled?
21
+ trace = NewRelic::Agent::Transaction.tl_current.transaction_trace
22
22
  trace.profile = ::RubyProf.stop
23
23
  end
24
24
  end
@@ -20,18 +20,41 @@ DependencyDetection.defer do
20
20
  # Client middleware has additional parameters, and our tests use the
21
21
  # middleware client-side to work inline.
22
22
  def call(worker, msg, queue, *_)
23
- perform_action_with_newrelic_trace(
24
- :name => 'perform',
25
- :class_name => msg['class'],
26
- :category => 'OtherTransaction/SidekiqJob') do
23
+ trace_args = if worker.respond_to?(:newrelic_trace_args)
24
+ worker.newrelic_trace_args(msg, queue)
25
+ else
26
+ self.class.default_trace_args(msg)
27
+ end
27
28
 
29
+ perform_action_with_newrelic_trace(trace_args) do
28
30
  if NewRelic::Agent.config[:'sidekiq.capture_params']
29
31
  NewRelic::Agent.add_custom_parameters(:job_arguments => msg['args'])
30
32
  end
31
-
32
33
  yield
33
34
  end
34
35
  end
36
+
37
+ def self.default_trace_args(msg)
38
+ {
39
+ :name => 'perform',
40
+ :class_name => msg['class'],
41
+ :category => 'OtherTransaction/SidekiqJob'
42
+ }
43
+ end
44
+ end
45
+
46
+ class Sidekiq::Extensions::DelayedClass
47
+ def newrelic_trace_args(msg, queue)
48
+ (target, method_name, args) = YAML.load(msg['args'][0])
49
+ {
50
+ :name => method_name,
51
+ :class_name => target.name,
52
+ :category => 'OtherTransaction/SidekiqJob'
53
+ }
54
+ rescue => e
55
+ NewRelic::Agent.logger.error("Failure during deserializing YAML for Sidekiq::Extensions::DelayedClass", e)
56
+ NewRelic::SidekiqInstrumentation.default_trace_args(msg)
57
+ end
35
58
  end
36
59
 
37
60
  Sidekiq.configure_server do |config|
@@ -75,7 +75,7 @@ module NewRelic
75
75
  include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
76
76
 
77
77
  # Expected method for supporting ControllerInstrumentation
78
- def newrelic_request_headers
78
+ def newrelic_request_headers(_)
79
79
  request.env
80
80
  end
81
81
 
@@ -136,12 +136,12 @@ module NewRelic
136
136
  route_eval_without_newrelic(*args, &block)
137
137
  end
138
138
 
139
- def dispatch_with_newrelic
139
+ def dispatch_with_newrelic #THREAD_LOCAL_ACCESS
140
140
  if ignore_request?
141
141
  env['newrelic.ignored'] = true
142
+ txn = ::NewRelic::Agent::Transaction.tl_current
143
+ txn.ignore! if txn
142
144
  return dispatch_without_newrelic
143
- elsif NewRelic::Agent::Transaction.current
144
- return dispatch_and_notice_errors_with_newrelic
145
145
  end
146
146
 
147
147
  name = TransactionNamer.initial_transaction_name(request)
@@ -60,8 +60,8 @@ module NewRelic::Agent::Instrumentation::TyphoeusTracing
60
60
  request.respond_to?(:hydra) && request.hydra
61
61
  end
62
62
 
63
- def self.trace(request)
64
- if NewRelic::Agent.is_execution_traced? && !request_is_hydra_enabled?(request)
63
+ def self.trace(request) #THREAD_LOCAL_ACCESS
64
+ if NewRelic::Agent.tl_is_execution_traced? && !request_is_hydra_enabled?(request)
65
65
  wrapped_request = ::NewRelic::Agent::HTTPClients::TyphoeusHTTPRequest.new(request)
66
66
  t0, segment = ::NewRelic::Agent::CrossAppTracing.start_trace(wrapped_request)
67
67
  callback = Proc.new do
@@ -70,5 +70,7 @@ module NewRelic::Agent::Instrumentation::TyphoeusTracing
70
70
  end
71
71
  request.on_complete.unshift(callback)
72
72
  end
73
+ rescue => e
74
+ NewRelic::Agent.logger.error("Exception during trace setup for Typhoeus request", e)
73
75
  end
74
76
  end
@@ -35,11 +35,7 @@ module NewRelic
35
35
  @obfuscator ||= NewRelic::Agent::Obfuscator.new(NewRelic::Agent.config[:license_key], RUM_KEY_LENGTH)
36
36
  end
37
37
 
38
- def current_transaction
39
- NewRelic::Agent::TransactionState.get.most_recent_transaction
40
- end
41
-
42
- def insert_js?
38
+ def js_enabled_and_ready?
43
39
  if !enabled?
44
40
  ::NewRelic::Agent.logger.log_once(:debug, :js_agent_disabled,
45
41
  "JS agent instrumentation is disabled.")
@@ -56,16 +52,25 @@ module NewRelic
56
52
  ::NewRelic::Agent.logger.log_once(:debug, :missing_browser_key,
57
53
  "Browser key is not set. Skipping browser instrumentation.")
58
54
  false
59
- elsif !current_transaction
55
+ else
56
+ true
57
+ end
58
+ rescue => e
59
+ ::NewRelic::Agent.logger.debug "Failure during 'js_enabled_and_ready?'", e
60
+ false
61
+ end
62
+
63
+ def insert_js?(state)
64
+ if !state.current_transaction
60
65
  ::NewRelic::Agent.logger.debug "Not in transaction. Skipping browser instrumentation."
61
66
  false
62
- elsif !::NewRelic::Agent.is_transaction_traced?
67
+ elsif !state.is_transaction_traced?
63
68
  ::NewRelic::Agent.logger.debug "Transaction is not traced. Skipping browser instrumentation."
64
69
  false
65
- elsif !::NewRelic::Agent.is_execution_traced?
70
+ elsif !state.is_execution_traced?
66
71
  ::NewRelic::Agent.logger.debug "Execution is not traced. Skipping browser instrumentation."
67
72
  false
68
- elsif ::NewRelic::Agent::TransactionState.get.request_ignore_enduser
73
+ elsif state.current_transaction.ignore_enduser?
69
74
  ::NewRelic::Agent.logger.debug "Ignore end user for this transaction is set. Skipping browser instrumentation."
70
75
  false
71
76
  else
@@ -81,29 +86,31 @@ module NewRelic
81
86
  value.nil? || value.empty?
82
87
  end
83
88
 
84
- def browser_timing_header
85
- return "" unless insert_js?
86
- bt_config = browser_timing_config
89
+ def browser_timing_header #THREAD_LOCAL_ACCESS
90
+ return '' unless js_enabled_and_ready? # fast exit
91
+
92
+ state = NewRelic::Agent::TransactionState.tl_get
93
+ return '' unless insert_js?(state) # slower exit
94
+
95
+ bt_config = browser_timing_config(state)
87
96
  return '' if bt_config.empty?
88
97
 
89
98
  bt_config + browser_timing_loader
90
99
  rescue => e
91
100
  ::NewRelic::Agent.logger.debug "Failure during RUM browser_timing_header construction", e
92
- ""
101
+ ''
93
102
  end
94
103
 
95
- # NOTE: Internal prototyping often overrides this, so leave name stable!
96
104
  def browser_timing_loader
97
105
  html_safe_if_needed("\n<script type=\"text/javascript\">#{Agent.config[:js_agent_loader]}</script>")
98
106
  end
99
107
 
100
- # NOTE: Internal prototyping often overrides this, so leave name stable!
101
- def browser_timing_config
102
- txn = TransactionState.get.most_recent_transaction
108
+ def browser_timing_config(state)
109
+ txn = state.current_transaction
103
110
  return '' if txn.nil?
104
111
 
105
112
  txn.freeze_name_and_execute_if_not_ignored do
106
- data = data_for_js_agent
113
+ data = data_for_js_agent(state)
107
114
  json = NewRelic::JSONWrapper.dump(data)
108
115
  return html_safe_if_needed("\n<script type=\"text/javascript\">window.NREUM||(NREUM={});NREUM.info=#{json}</script>")
109
116
  end
@@ -125,8 +132,7 @@ module NewRelic
125
132
  SSL_FOR_HTTP_KEY = "sslForHttp".freeze
126
133
 
127
134
  # NOTE: Internal prototyping may override this, so leave name stable!
128
- def data_for_js_agent
129
- state = NewRelic::Agent::TransactionState.get
135
+ def data_for_js_agent(state)
130
136
  timings = state.timings
131
137
 
132
138
  data = {
@@ -143,7 +149,7 @@ module NewRelic
143
149
  }
144
150
 
145
151
  add_ssl_for_http(data)
146
- add_user_attributes(data)
152
+ add_user_attributes(data, state.current_transaction)
147
153
 
148
154
  data
149
155
  end
@@ -155,10 +161,10 @@ module NewRelic
155
161
  end
156
162
  end
157
163
 
158
- def add_user_attributes(data)
159
- return unless include_custom_parameters?
164
+ def add_user_attributes(data, txn)
165
+ return unless include_custom_parameters?(txn)
160
166
 
161
- params = event_params(current_transaction.custom_parameters)
167
+ params = event_params(txn.custom_parameters)
162
168
  json = NewRelic::JSONWrapper.dump(params)
163
169
  data[USER_ATTRIBUTES_KEY] = obfuscator.obfuscate(json)
164
170
  end
@@ -166,16 +172,14 @@ module NewRelic
166
172
  # Still support deprecated capture_attributes.page_view_events for
167
173
  # clients that use it. Could potentially be removed if we don't have
168
174
  # anymore users with it set according to zeitgeist.
169
- def include_custom_parameters?
170
- has_custom_parameters? &&
175
+ def include_custom_parameters?(txn)
176
+ has_custom_parameters?(txn) &&
171
177
  (NewRelic::Agent.config[:'browser_monitoring.capture_attributes'] ||
172
178
  NewRelic::Agent.config[:'capture_attributes.page_view_events'])
173
179
  end
174
180
 
175
- def has_custom_parameters?
176
- current_transaction &&
177
- current_transaction.custom_parameters &&
178
- !current_transaction.custom_parameters.empty?
181
+ def has_custom_parameters?(txn)
182
+ txn && txn.custom_parameters && !txn.custom_parameters.empty?
179
183
  end
180
184
 
181
185
  def html_safe_if_needed(string)
@@ -17,24 +17,24 @@ module NewRelic
17
17
 
18
18
  attr_accessor :messages, :level
19
19
 
20
- def fatal(*msgs)
21
- messages << [:fatal, msgs]
20
+ def fatal(*msgs, &blk)
21
+ messages << [:fatal, msgs, blk]
22
22
  end
23
23
 
24
- def error(*msgs)
25
- messages << [:error, msgs]
24
+ def error(*msgs, &blk)
25
+ messages << [:error, msgs, blk]
26
26
  end
27
27
 
28
- def warn(*msgs)
29
- messages << [:warn, msgs]
28
+ def warn(*msgs, &blk)
29
+ messages << [:warn, msgs, blk]
30
30
  end
31
31
 
32
- def info(*msgs)
33
- messages << [:info, msgs]
32
+ def info(*msgs, &blk)
33
+ messages << [:info, msgs, blk]
34
34
  end
35
35
 
36
- def debug(*msgs)
37
- messages << [:debug, msgs]
36
+ def debug(*msgs, &blk)
37
+ messages << [:debug, msgs, blk]
38
38
  end
39
39
 
40
40
  def log_exception(level, e, backtrace_level=level)
@@ -42,8 +42,8 @@ module NewRelic
42
42
  end
43
43
 
44
44
  def dump(logger)
45
- messages.each do |(method, args)|
46
- logger.send(method, *args)
45
+ messages.each do |(method, args, blk)|
46
+ logger.send(method, *args, &blk)
47
47
  end
48
48
  messages.clear
49
49
  end
@@ -72,14 +72,14 @@ module NewRelic
72
72
  #
73
73
  # @api public
74
74
  #
75
- def trace_execution_unscoped(metric_names, options={})
76
- return yield unless NewRelic::Agent.is_execution_traced?
75
+ def trace_execution_unscoped(metric_names, options={}) #THREAD_LOCAL_ACCESS
76
+ return yield unless NewRelic::Agent.tl_is_execution_traced?
77
77
  t0 = Time.now
78
78
  begin
79
79
  yield
80
80
  ensure
81
81
  duration = (Time.now - t0).to_f # for some reason this is 3 usec faster than Time - Time
82
- stat_engine.record_metrics(metric_names, duration)
82
+ stat_engine.tl_record_unscoped_metrics(metric_names, duration)
83
83
  end
84
84
  end
85
85
 
@@ -107,11 +107,6 @@ module NewRelic
107
107
  NewRelic::Agent.instance
108
108
  end
109
109
 
110
- # Shorthand to return the status of tracing
111
- def traced?
112
- NewRelic::Agent.is_execution_traced?
113
- end
114
-
115
110
  # Shorthand to return the current statistics engine
116
111
  def stat_engine
117
112
  agent_instance.stats_engine
@@ -149,41 +144,28 @@ module NewRelic
149
144
  # the frame so that we can check for it later, to maintain
150
145
  # sanity. If the frame stack becomes unbalanced, this
151
146
  # transaction loses meaning.
152
- def trace_execution_scoped_header(options, t0=Time.now.to_f)
153
- frame = log_errors("trace_execution_scoped header") do
154
- NewRelic::Agent::TracedMethodStack.push_frame(:method_tracer, t0, options[:deduct_call_time_from_parent])
147
+ def trace_execution_scoped_header(state, t0)
148
+ log_errors(:trace_execution_scoped_header) do
149
+ stack = state.traced_method_stack
150
+ stack.push_frame(state, :method_tracer, t0)
155
151
  end
156
- # needed in case we have an error, above, to always return
157
- # the start time.
158
- [t0, frame]
159
152
  end
160
153
 
161
- def metrics_for_current_transaction(first_name, other_names, options)
154
+ def record_metrics(state, first_name, other_names, duration, exclusive, options)
162
155
  # The default value for :scoped_metric is true, so set it as true
163
156
  # if it was unset.
164
- options[:scoped_metric] = true if options[:scoped_metric].nil?
165
-
166
- metrics = []
167
-
168
- if !options[:scoped_metric_only]
169
- metrics += other_names.map { |n| NewRelic::MetricSpec.new(n) }
170
- end
157
+ record_scoped_metric = options.has_key?(:scoped_metric) ? options[:scoped_metric] : true
171
158
 
172
159
  if options[:metric]
173
- if !options[:scoped_metric_only]
174
- metrics << NewRelic::MetricSpec.new(first_name)
175
- end
176
- if NewRelic::Agent::Transaction.in_transaction? && options[:scoped_metric]
177
- metrics << NewRelic::MetricSpec.new(first_name, StatsEngine::MetricStats::SCOPE_PLACEHOLDER)
160
+ if record_scoped_metric
161
+ stat_engine.record_scoped_and_unscoped_metrics(state, first_name, other_names, duration, exclusive)
162
+ else
163
+ metrics = [first_name].concat(other_names)
164
+ stat_engine.record_unscoped_metrics(state, metrics, duration, exclusive)
178
165
  end
166
+ else
167
+ stat_engine.record_unscoped_metrics(state, other_names, duration, exclusive)
179
168
  end
180
-
181
- metrics
182
- end
183
-
184
- def record_metrics(first_name, other_names, duration, exclusive, options)
185
- metrics = metrics_for_current_transaction(first_name, other_names, options)
186
- stat_engine.record_metrics_internal(metrics, duration, exclusive)
187
169
  end
188
170
 
189
171
  # Handles the end of the #trace_execution_scoped method -
@@ -194,13 +176,14 @@ module NewRelic
194
176
  # this method fails safely if the header does not manage to
195
177
  # push the scope onto the stack - it simply does not trace
196
178
  # any metrics.
197
- def trace_execution_scoped_footer(t0, first_name, metric_names, expected_frame, options, t1=Time.now.to_f)
198
- log_errors("trace_method_execution footer") do
179
+ def trace_execution_scoped_footer(state, t0, first_name, metric_names, expected_frame, options, t1=Time.now.to_f)
180
+ log_errors(:trace_method_execution_footer) do
199
181
  if expected_frame
200
- frame = NewRelic::Agent::TracedMethodStack.pop_frame(expected_frame, first_name, t1)
182
+ stack = state.traced_method_stack
183
+ frame = stack.pop_frame(state, expected_frame, first_name, t1, !!options[:metric])
201
184
  duration = t1 - t0
202
185
  exclusive = duration - frame.children_time
203
- record_metrics(first_name, metric_names, duration, exclusive, options)
186
+ record_metrics(state, first_name, metric_names, duration, exclusive, options)
204
187
  end
205
188
  end
206
189
  end
@@ -219,24 +202,25 @@ module NewRelic
219
202
  #
220
203
  # @api public
221
204
  #
222
- def trace_execution_scoped(metric_names, options={})
223
- return yield unless traced?
205
+ def trace_execution_scoped(metric_names, options={}) #THREAD_LOCAL_ACCESS
206
+ state = NewRelic::Agent::TransactionState.tl_get
207
+ return yield unless state.is_execution_traced?
224
208
 
225
209
  metric_names = Array(metric_names)
226
210
  first_name = metric_names.shift
227
211
  return yield if first_name.nil?
228
212
 
229
213
  set_if_nil(options, :metric)
230
- set_if_nil(options, :deduct_call_time_from_parent)
231
214
  additional_metrics_callback = options[:additional_metrics_callback]
232
- start_time, expected_scope = trace_execution_scoped_header(options)
215
+ start_time = Time.now.to_f
216
+ expected_scope = trace_execution_scoped_header(state, start_time)
233
217
 
234
218
  begin
235
219
  result = yield
236
220
  metric_names += Array(additional_metrics_callback.call) if additional_metrics_callback
237
221
  result
238
222
  ensure
239
- trace_execution_scoped_footer(start_time, first_name, metric_names, expected_scope, options)
223
+ trace_execution_scoped_footer(state, start_time, first_name, metric_names, expected_scope, options)
240
224
  end
241
225
  end
242
226
 
@@ -245,9 +229,9 @@ module NewRelic
245
229
  module ClassMethods
246
230
  # contains methods refactored out of the #add_method_tracer method
247
231
  module AddMethodTracer
248
- ALLOWED_KEYS = [:force, :metric, :push_scope, :deduct_call_time_from_parent, :code_header, :code_footer, :scoped_metric_only].freeze
232
+ ALLOWED_KEYS = [:force, :metric, :push_scope, :code_header, :code_footer].freeze
249
233
 
250
- DEPRECATED_KEYS = [:force].freeze
234
+ DEPRECATED_KEYS = [:force, :scoped_metric_only, :deduct_call_time_from_parent].freeze
251
235
 
252
236
  # raises an error when the
253
237
  # NewRelic::Agent::MethodTracer::ClassMethods#add_method_tracer
@@ -268,16 +252,6 @@ module NewRelic
268
252
  end
269
253
  end
270
254
 
271
- # Sets the options for deducting call time from
272
- # parents. This defaults to true if we are recording a metric, but
273
- # can be overridden by the user if desired.
274
- #
275
- # has the effect of not allowing overlapping times, and
276
- # should generally be true
277
- def set_deduct_call_time_based_on_metric(options)
278
- {:deduct_call_time_from_parent => !!options[:metric]}.merge(options)
279
- end
280
-
281
255
  # validity checking - add_method_tracer must receive either
282
256
  # push scope or metric, or else it would record no
283
257
  # data. Raises an error if this is the case
@@ -287,7 +261,7 @@ module NewRelic
287
261
  end
288
262
  end
289
263
 
290
- DEFAULT_SETTINGS = {:push_scope => true, :metric => true, :code_header => "", :code_footer => "", :scoped_metric_only => false}.freeze
264
+ DEFAULT_SETTINGS = {:push_scope => true, :metric => true, :code_header => "", :code_footer => "" }.freeze
291
265
 
292
266
  # Checks the provided options to make sure that they make
293
267
  # sense. Raises an error if the options are incorrect to
@@ -298,7 +272,7 @@ module NewRelic
298
272
  raise TypeError.new("Error adding method tracer to #{method_name}: provided options must be a Hash")
299
273
  end
300
274
  check_for_illegal_keys!(method_name, options)
301
- options = set_deduct_call_time_based_on_metric(DEFAULT_SETTINGS.merge(options))
275
+ options = DEFAULT_SETTINGS.merge(options)
302
276
  check_for_push_scope_and_metric(options)
303
277
  options
304
278
  end
@@ -335,7 +309,7 @@ module NewRelic
335
309
  # instrumentation into effectively one method call overhead
336
310
  # when the agent is disabled
337
311
  def assemble_code_header(method_name, metric_name_code, options)
338
- header = "return #{_untraced_method_name(method_name, metric_name_code)}(*args, &block) unless NewRelic::Agent.is_execution_traced?\n"
312
+ header = "return #{_untraced_method_name(method_name, metric_name_code)}(*args, &block) unless NewRelic::Agent.tl_is_execution_traced?\n"
339
313
 
340
314
  header += options[:code_header].to_s
341
315
 
@@ -385,9 +359,7 @@ module NewRelic
385
359
  "def #{_traced_method_name(method_name, metric_name_code)}(*args, &block)
386
360
  #{options[:code_header]}
387
361
  result = #{klass}.trace_execution_scoped(\"#{metric_name_code}\",
388
- :metric => #{options[:metric]},
389
- :deduct_call_time_from_parent => #{options[:deduct_call_time_from_parent]},
390
- :scoped_metric_only => #{options[:scoped_metric_only]}) do
362
+ :metric => #{options[:metric]}) do
391
363
  #{_untraced_method_name(method_name, metric_name_code)}(*args, &block)
392
364
  end
393
365
  #{options[:code_footer]}
@@ -412,7 +384,7 @@ module NewRelic
412
384
 
413
385
  # Add a method tracer to the specified method.
414
386
  #
415
- # === Common Options
387
+ # === Options
416
388
  #
417
389
  # * <tt>:push_scope => false</tt> specifies this method tracer should not
418
390
  # keep track of the caller; it will not show up in controller breakdown
@@ -423,18 +395,6 @@ module NewRelic
423
395
  #
424
396
  # === Uncommon Options
425
397
  #
426
- # * <tt>:scoped_metric_only => true</tt> indicates that the unscoped metric
427
- # should not be recorded. Normally two metrics are potentially created
428
- # on every invocation: the aggregate method where statistics for all calls
429
- # of that metric are stored, and the "scoped metric" which records the
430
- # statistics for invocations in a particular scope--generally a controller
431
- # action. This option indicates that only the second type should be recorded.
432
- # The effect is similar to <tt>:metric => false</tt> but in addition you
433
- # will also see the invocation in breakdown pie charts.
434
- # * <tt>:deduct_call_time_from_parent => false</tt> indicates that the method invocation
435
- # time should never be deducted from the time reported as 'exclusive' in the
436
- # caller. You would want to use this if you are tracing a recursive method
437
- # or a method that might be called inside another traced method.
438
398
  # * <tt>:code_header</tt> and <tt>:code_footer</tt> specify ruby code that
439
399
  # is inserted into the tracer before and after the call.
440
400
  #