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
@@ -2,7 +2,8 @@
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
 
5
- require 'new_relic/rack/transaction_reset'
5
+ require 'new_relic/rack/agent_middleware'
6
+ require 'new_relic/agent/instrumentation/middleware_proxy'
6
7
 
7
8
  module NewRelic::Rack
8
9
  # This middleware is used by the agent in order to capture exceptions that
@@ -12,13 +13,7 @@ module NewRelic::Rack
12
13
  #
13
14
  # @api public
14
15
  #
15
- class ErrorCollector
16
- def initialize(app, options={})
17
- @app = app
18
- end
19
-
20
- include TransactionReset
21
-
16
+ class ErrorCollector < AgentMiddleware
22
17
  def params_from_env(env)
23
18
  if defined?(ActionDispatch::Request)
24
19
  # We use ActionDispatch::Request if it's available so that we can get
@@ -50,56 +45,23 @@ module NewRelic::Rack
50
45
  strip_query_string(env['HTTP_REFERER'].to_s)
51
46
  end
52
47
 
53
- def call(env)
54
- ensure_transaction_reset(env)
55
- @app.call(env)
56
- rescue Exception => exception
57
- NewRelic::Agent.logger.debug "collecting %p: %s" % [ exception.class, exception.message ]
58
- if !should_ignore_error?(exception, env)
59
- NewRelic::Agent.notice_error(exception,
60
- :uri => uri_from_env(env),
61
- :referer => referrer_from_env(env),
62
- :request_params => params_from_env(env))
63
- end
64
- raise exception
65
- end
66
-
67
- def should_ignore_error?(error, env)
68
- NewRelic::Agent.instance.error_collector.error_is_ignored?(error) ||
69
- ignored_in_controller?(error, env)
70
- end
71
-
72
- def ignored_in_controller?(exception, env)
73
- return true if env['newrelic.ignored']
74
-
75
- if env['action_dispatch.request.parameters']
76
- ignore_actions = newrelic_ignore_for_controller(env['action_dispatch.request.parameters']['controller'])
77
- action_name = env['action_dispatch.request.parameters']['action']
78
-
79
- case ignore_actions
80
- when nil; false
81
- when Hash
82
- only_actions = Array(ignore_actions[:only])
83
- except_actions = Array(ignore_actions[:except])
84
- only_actions.include?(action_name.to_sym) ||
85
- (except_actions.any? &&
86
- !except_actions.include?(action_name.to_sym))
87
- else
88
- true
48
+ def traced_call(env)
49
+ begin
50
+ @app.call(env)
51
+ rescue Exception => exception
52
+ NewRelic::Agent.logger.debug "collecting %p: %s" % [ exception.class, exception.message ]
53
+ if !should_ignore_error?(exception, env)
54
+ NewRelic::Agent.notice_error(exception,
55
+ :uri => uri_from_env(env),
56
+ :referer => referrer_from_env(env),
57
+ :request_params => params_from_env(env))
89
58
  end
59
+ raise exception
90
60
  end
91
61
  end
92
62
 
93
- def newrelic_ignore_for_controller(controller_name)
94
- if controller_name
95
- controller_constant_name = (controller_name + "_controller").camelize
96
- if Object.const_defined?(controller_constant_name)
97
- controller = controller_constant_name.constantize
98
- controller.instance_variable_get(:@do_not_trace)
99
- end
100
- end
101
- rescue NameError
102
- nil
63
+ def should_ignore_error?(error, env)
64
+ NewRelic::Agent.instance.error_collector.error_is_ignored?(error)
103
65
  end
104
66
  end
105
67
  end
@@ -2,116 +2,23 @@
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
 
5
- # When installed as a plugin this is loaded automatically.
5
+ # When installed as a plugin, this is loaded automatically.
6
6
  #
7
7
  # When installed as a gem, you need to add
8
8
  # require 'new_relic/recipes'
9
- # to your deploy.rb
9
+ # to deploy.rb
10
10
  #
11
- # Defined deploy:notify_rpm which will send information about the deploy to New Relic.
12
- # The task will run on app servers except where no_release is true.
13
- # If it fails, it will not affect the task execution or do a rollback.
11
+ # Defines newrelic:notice_deployment, which sends information about the deploy
12
+ # to New Relic. The task will run on all app release roles. If it fails, it will
13
+ # not affect the execution of subsequent tasks or cause a rollback.
14
14
  #
15
15
  # @api public
16
16
  #
17
- make_notify_task = Proc.new do
18
-
19
- namespace :newrelic do
20
-
21
- # on all deployments, notify New Relic
22
- desc "Record a deployment in New Relic (newrelic.com)"
23
- task :notice_deployment, :roles => :app, :except => {:no_release => true } do
24
- rails_env = fetch(:newrelic_rails_env, fetch(:rails_env, "production"))
25
-
26
- require File.join(File.dirname(__FILE__), 'cli', 'command.rb')
27
-
28
- begin
29
- # allow overrides to be defined for revision, description, changelog, appname, and user
30
- rev = fetch(:newrelic_revision) if exists?(:newrelic_revision)
31
- description = fetch(:newrelic_desc) if exists?(:newrelic_desc)
32
- changelog = fetch(:newrelic_changelog) if exists?(:newrelic_changelog)
33
- appname = fetch(:newrelic_appname) if exists?(:newrelic_appname)
34
- user = fetch(:newrelic_user) if exists?(:newrelic_user)
35
- license_key = fetch(:newrelic_license_key) if exists?(:newrelic_license_key)
36
-
37
- unless scm.to_sym == :none
38
- changelog = lookup_changelog(changelog)
39
- rev = lookup_rev(rev)
40
- end
41
-
42
- new_revision = rev
43
- deploy_options = {
44
- :environment => rails_env,
45
- :revision => new_revision,
46
- :changelog => changelog,
47
- :description => description,
48
- :appname => appname,
49
- :user => user,
50
- :license_key => license_key
51
- }
52
-
53
- logger.debug "Uploading deployment to New Relic"
54
- deployment = NewRelic::Cli::Deployments.new deploy_options
55
- deployment.run
56
- logger.info "Uploaded deployment information to New Relic"
57
-
58
- rescue NewRelic::Cli::Command::CommandFailure => e
59
- logger.info e.message
60
-
61
- rescue Capistrano::CommandError
62
- logger.info "Unable to notify New Relic of the deployment... skipping"
63
-
64
- rescue => e
65
- logger.info "Error creating New Relic deployment (#{e})\n#{e.backtrace.join("\n")}"
66
- end
67
-
68
- # WIP: For rollbacks, let's update the deployment we created with an indication of the failure:
69
- # on_rollback do
70
- # run(...)
71
- # end
72
- end
73
-
74
- def lookup_changelog(changelog)
75
- if !changelog
76
- logger.debug "Getting log of changes for New Relic Deployment details"
77
- from_revision = source.next_revision(current_revision)
78
-
79
- if scm.to_sym == :git
80
- log_command = "git log --no-color --pretty=format:' * %an: %s' " +
81
- "--abbrev-commit --no-merges #{previous_revision}..#{real_revision}"
82
- else
83
- log_command = "#{source.log(from_revision)}"
84
- end
85
-
86
- changelog = `#{log_command}`
87
- end
88
- changelog
89
- end
90
-
91
- def lookup_rev(rev)
92
- if rev.nil?
93
- rev = source.query_revision(source.head()) do |cmd|
94
- logger.debug "executing locally: '#{cmd}'"
95
- `#{cmd}`
96
- end
97
-
98
- rev = rev[0..6] if scm.to_sym == :git
99
- end
100
- rev
101
- end
102
- end
103
- end
104
17
 
105
18
  require 'capistrano/version'
106
19
 
107
- if defined?(Capistrano::Version::MAJOR) && Capistrano::Version::MAJOR < 2
108
- STDERR.puts "Unable to load #{__FILE__}\nNew Relic Capistrano hooks require at least version 2.0.0"
20
+ if defined?(Capistrano::VERSION) && Capistrano::VERSION.to_s.split('.').first.to_i >= 3
21
+ require 'new_relic/recipes/capistrano3'
109
22
  else
110
- instance = Capistrano::Configuration.instance
111
-
112
- if instance
113
- instance.load &make_notify_task
114
- else
115
- make_notify_task.call
116
- end
23
+ require 'new_relic/recipes/capistrano_legacy'
117
24
  end
@@ -0,0 +1,66 @@
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 'capistrano/framework'
6
+
7
+ namespace :newrelic do
8
+
9
+ # notifies New Relic of a deployment
10
+ desc "Record a deployment in New Relic (newrelic.com)"
11
+ task :notice_deployment do
12
+ on roles(:app) do
13
+ rails_env = fetch(:newrelic_rails_env, fetch(:rails_env, "production"))
14
+
15
+ require 'new_relic/cli/command.rb'
16
+
17
+ begin
18
+ # allow overrides to be defined for revision, description, changelog, appname, and user
19
+ rev = fetch(:newrelic_revision)
20
+ description = fetch(:newrelic_desc)
21
+ changelog = fetch(:newrelic_changelog)
22
+ appname = fetch(:newrelic_appname)
23
+ user = fetch(:newrelic_user)
24
+ license_key = fetch(:newrelic_license_key)
25
+
26
+ unless scm == :none
27
+ changelog ||= lookup_changelog
28
+ rev = fetch(:current_revision)
29
+ end
30
+
31
+ new_revision = rev
32
+ deploy_options = {
33
+ :environment => rails_env,
34
+ :revision => new_revision,
35
+ :changelog => changelog,
36
+ :description => description,
37
+ :appname => appname,
38
+ :user => user,
39
+ :license_key => license_key
40
+ }
41
+
42
+ debug "Uploading deployment to New Relic"
43
+ deployment = NewRelic::Cli::Deployments.new deploy_options
44
+ deployment.run
45
+ info "Uploaded deployment information to New Relic"
46
+
47
+ rescue NewRelic::Cli::Command::CommandFailure => e
48
+ info e.message
49
+ rescue => e
50
+ info "Error creating New Relic deployment (#{e})\n#{e.backtrace.join("\n")}"
51
+ end
52
+ end
53
+ end
54
+
55
+ def lookup_changelog
56
+ debug "Retrieving changelog for New Relic Deployment details"
57
+ previous_revision = fetch(:previous_revision)
58
+ current_revision = fetch(:current_revision)
59
+
60
+ if scm == :git
61
+ log_command = "git log --no-color --pretty=format:' * %an: %s' " +
62
+ "--abbrev-commit --no-merges #{previous_revision}..#{current_revision}"
63
+ `#{log_command}`
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,98 @@
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
+ make_notify_task = Proc.new do
6
+
7
+ namespace :newrelic do
8
+
9
+ # on all deployments, notify New Relic
10
+ desc "Record a deployment in New Relic (newrelic.com)"
11
+ task :notice_deployment, :roles => :app, :except => {:no_release => true } do
12
+ rails_env = fetch(:newrelic_rails_env, fetch(:rails_env, "production"))
13
+
14
+ require 'new_relic/cli/command'
15
+
16
+ begin
17
+ # allow overrides to be defined for revision, description, changelog, appname, and user
18
+ rev = fetch(:newrelic_revision) if exists?(:newrelic_revision)
19
+ description = fetch(:newrelic_desc) if exists?(:newrelic_desc)
20
+ changelog = fetch(:newrelic_changelog) if exists?(:newrelic_changelog)
21
+ appname = fetch(:newrelic_appname) if exists?(:newrelic_appname)
22
+ user = fetch(:newrelic_user) if exists?(:newrelic_user)
23
+ license_key = fetch(:newrelic_license_key) if exists?(:newrelic_license_key)
24
+
25
+ unless scm == :none
26
+ changelog = lookup_changelog(changelog)
27
+ rev = lookup_rev(rev)
28
+ end
29
+
30
+ new_revision = rev
31
+ deploy_options = {
32
+ :environment => rails_env,
33
+ :revision => new_revision,
34
+ :changelog => changelog,
35
+ :description => description,
36
+ :appname => appname,
37
+ :user => user,
38
+ :license_key => license_key
39
+ }
40
+
41
+ logger.debug "Uploading deployment to New Relic"
42
+ deployment = NewRelic::Cli::Deployments.new deploy_options
43
+ deployment.run
44
+ logger.info "Uploaded deployment information to New Relic"
45
+
46
+ rescue NewRelic::Cli::Command::CommandFailure => e
47
+ logger.info e.message
48
+ rescue Capistrano::CommandError
49
+ logger.info "Unable to notify New Relic of the deployment... skipping"
50
+ rescue => e
51
+ logger.info "Error creating New Relic deployment (#{e})\n#{e.backtrace.join("\n")}"
52
+ end
53
+ end
54
+
55
+ def lookup_changelog(changelog)
56
+ if !changelog
57
+ logger.debug "Getting log of changes for New Relic Deployment details"
58
+ from_revision = source.next_revision(current_revision)
59
+
60
+ if scm == :git
61
+ log_command = "git log --no-color --pretty=format:' * %an: %s' " +
62
+ "--abbrev-commit --no-merges #{previous_revision}..#{real_revision}"
63
+ else
64
+ log_command = "#{source.log(from_revision)}"
65
+ end
66
+
67
+ changelog = `#{log_command}`
68
+ end
69
+ changelog
70
+ end
71
+
72
+ def lookup_rev(rev)
73
+ if rev.nil?
74
+ rev = source.query_revision(source.head()) do |cmd|
75
+ logger.debug "executing locally: '#{cmd}'"
76
+ `#{cmd}`
77
+ end
78
+
79
+ rev = rev[0..6] if scm == :git
80
+ end
81
+ rev
82
+ end
83
+ end
84
+ end
85
+
86
+ require 'capistrano/version'
87
+
88
+ if defined?(Capistrano::Version::MAJOR) && Capistrano::Version::MAJOR < 2
89
+ STDERR.puts "Unable to load #{__FILE__}\nNew Relic Capistrano hooks require at least version 2.0.0"
90
+ else
91
+ instance = Capistrano::Configuration.instance
92
+
93
+ if instance
94
+ instance.load &make_notify_task
95
+ else
96
+ make_notify_task.call
97
+ end
98
+ end
@@ -101,11 +101,11 @@ module NewRelic
101
101
  end
102
102
 
103
103
  # relative_timestamp is seconds since the start of the transaction
104
- def create_segment(relative_timestamp, metric_name=nil, segment_id = nil)
104
+ def create_segment(relative_timestamp, metric_name=nil)
105
105
  raise TypeError.new("Frozen Transaction Sample") if finished
106
106
  @params[:segment_count] += 1
107
107
  @segment_count += 1
108
- NewRelic::TransactionSample::Segment.new(relative_timestamp, metric_name, segment_id)
108
+ NewRelic::TransactionSample::Segment.new(relative_timestamp, metric_name)
109
109
  end
110
110
 
111
111
  def duration
@@ -156,25 +156,6 @@ module NewRelic
156
156
  s << @root_segment.to_debug_str(0)
157
157
  end
158
158
 
159
- # return a new transaction sample that treats segments
160
- # with the given regular expression in their name as if they
161
- # were never called at all. This allows us to strip out segments
162
- # from traces captured in development environment that would not
163
- # normally show up in production (like Rails/Application Code Loading)
164
- def omit_segments_with(regex)
165
- regex = Regexp.new(regex)
166
-
167
- sample = TransactionSample.new(@start_time, sample_id)
168
-
169
- sample.params = params.dup
170
- sample.params[:segment_count] = 0
171
-
172
- delta = build_segment_with_omissions(sample, 0.0, @root_segment, sample.root_segment, regex)
173
- sample.root_segment.end_trace(@root_segment.exit_timestamp - delta)
174
- sample.profile = self.profile
175
- sample
176
- end
177
-
178
159
  # Return a new transaction sample that can be sent to the New
179
160
  # Relic service.
180
161
  def prepare_to_send!
@@ -195,43 +176,14 @@ module NewRelic
195
176
  @params = params
196
177
  end
197
178
 
198
- def force_persist_sample?
199
- NewRelic::Agent::TransactionState.get.request_token &&
200
- self.duration > NewRelic::Agent::TransactionState.get.current_transaction.apdex_t
179
+ def force_persist_sample? #THREAD_LOCAL_ACCESS
180
+ state = NewRelic::Agent::TransactionState.tl_get
181
+
182
+ state.request_token && self.duration > state.current_transaction.apdex_t
201
183
  end
202
184
 
203
185
  private
204
186
 
205
- # This is badly in need of refactoring
206
- def build_segment_with_omissions(new_sample, time_delta, source_segment, target_segment, regex)
207
- source_segment.called_segments.each do |source_called_segment|
208
- # if this segment's metric name matches the given regular expression, bail
209
- # here and increase the amount of time that we reduce the target sample with
210
- # by this omitted segment's duration.
211
- do_omit = regex =~ source_called_segment.metric_name
212
-
213
- if do_omit
214
- time_delta += source_called_segment.duration
215
- else
216
- target_called_segment = new_sample.create_segment(
217
- source_called_segment.entry_timestamp - time_delta,
218
- source_called_segment.metric_name,
219
- source_called_segment.segment_id)
220
-
221
- target_segment.add_called_segment target_called_segment
222
- source_called_segment.params.each do |k,v|
223
- target_called_segment[k]=v
224
- end
225
-
226
- time_delta = build_segment_with_omissions(
227
- new_sample, time_delta, source_called_segment, target_called_segment, regex)
228
- target_called_segment.end_trace(source_called_segment.exit_timestamp - time_delta)
229
- end
230
- end
231
-
232
- return time_delta
233
- end
234
-
235
187
  def strip_sql!
236
188
  each_segment do |segment|
237
189
  segment.params.delete(:sql)