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
@@ -0,0 +1,84 @@
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 'rack'
6
+
7
+ class RackMiddleware < Performance::TestCase
8
+ class TestMiddleware
9
+ def initialize(app)
10
+ @app = app
11
+ end
12
+
13
+ def call(env)
14
+ @app.call(env)
15
+ end
16
+ end
17
+
18
+ # We want 10 middlewares each with different names so that we end up with
19
+ # different metric names for each one. This is more realistic than using the
20
+ # same name 10 times.
21
+ class TestMiddlewareA < TestMiddleware; def call(e); @app.call(e); end; end
22
+ class TestMiddlewareB < TestMiddleware; def call(e); @app.call(e); end; end
23
+ class TestMiddlewareC < TestMiddleware; def call(e); @app.call(e); end; end
24
+ class TestMiddlewareD < TestMiddleware; def call(e); @app.call(e); end; end
25
+ class TestMiddlewareE < TestMiddleware; def call(e); @app.call(e); end; end
26
+ class TestMiddlewareF < TestMiddleware; def call(e); @app.call(e); end; end
27
+ class TestMiddlewareG < TestMiddleware; def call(e); @app.call(e); end; end
28
+ class TestMiddlewareH < TestMiddleware; def call(e); @app.call(e); end; end
29
+ class TestMiddlewareI < TestMiddleware; def call(e); @app.call(e); end; end
30
+ class TestMiddlewareJ < TestMiddleware; def call(e); @app.call(e); end; end
31
+
32
+ class TestApp
33
+ def call(env)
34
+ [200, { 'Content-Type' => 'text/html' }, ['<body>hi</body>']]
35
+ end
36
+ end
37
+
38
+ def setup
39
+ require 'new_relic/rack/browser_monitoring'
40
+ require 'new_relic/rack/error_collector'
41
+ require 'new_relic/rack/agent_hooks'
42
+
43
+ NewRelic::Agent.manual_start(
44
+ :developer_mode => false,
45
+ :monitor_mode => false
46
+ )
47
+
48
+ @config = {
49
+ :beacon => 'beacon',
50
+ :disable_mobile_headers => false,
51
+ :browser_key => 'browserKey',
52
+ :js_agent_loader => 'loader',
53
+ :application_id => '5, 6', # collector can return app multiple ids
54
+ :'rum.enabled' => true,
55
+ :episodes_file => 'this_is_my_file',
56
+ :license_key => 'a' * 40
57
+ }
58
+ NewRelic::Agent.config.add_config_for_testing(@config)
59
+
60
+ @stack = Rack::Builder.new do
61
+ use TestMiddlewareA
62
+ use TestMiddlewareB
63
+ use TestMiddlewareC
64
+ use TestMiddlewareD
65
+ use TestMiddlewareE
66
+ use TestMiddlewareF
67
+ use TestMiddlewareG
68
+ use TestMiddlewareH
69
+ use TestMiddlewareI
70
+ use TestMiddlewareJ
71
+ use NewRelic::Rack::AgentHooks
72
+ use NewRelic::Rack::BrowserMonitoring
73
+ use NewRelic::Rack::ErrorCollector
74
+ run TestApp.new
75
+ end.to_app
76
+ @env = {}
77
+ end
78
+
79
+ def test_basic_middleware_stack()
80
+ iterations.times do
81
+ @stack.call(@env.dup)
82
+ end
83
+ end
84
+ end
@@ -21,7 +21,7 @@ class RumAutoInsertion < Performance::TestCase
21
21
  :episodes_file => 'this_is_my_file',
22
22
  :license_key => 'a' * 40
23
23
  }
24
- NewRelic::Agent.config.apply_config(@config)
24
+ NewRelic::Agent.config.add_config_for_testing(@config)
25
25
 
26
26
  @browser_monitor = NewRelic::Rack::BrowserMonitoring.new(nil)
27
27
  @html = "<html><head>#{'<script>alert("boo");</script>' * 1_000}</head><body></body></html>"
@@ -30,7 +30,7 @@ class ThreadProfiling < Performance::TestCase
30
30
  @nthreads.times do
31
31
  @threads << Thread.new do
32
32
  @threadq << self
33
- transaction_state = NewRelic::Agent::TransactionState.get
33
+ transaction_state = NewRelic::Agent::TransactionState.tl_get
34
34
  def transaction_state.in_request_transaction?; true; end
35
35
  recurse(50, method(:block))
36
36
  end
data/test/test_helper.rb CHANGED
@@ -193,15 +193,16 @@ module TransactionSampleTestHelper
193
193
  module_function
194
194
  def make_sql_transaction(*sql)
195
195
  sampler = nil
196
+ state = NewRelic::Agent::TransactionState.tl_get
196
197
 
197
198
  in_transaction('/path') do
198
199
  sampler = NewRelic::Agent.instance.transaction_sampler
199
- sampler.notice_push_frame "a"
200
+ sampler.notice_push_frame(state, "a")
200
201
  explainer = NewRelic::Agent::Instrumentation::ActiveRecord::EXPLAINER
201
- sql.each {|sql_statement| sampler.notice_sql(sql_statement, {:adapter => "mysql"}, 0, &explainer) }
202
+ sql.each {|sql_statement| sampler.notice_sql(sql_statement, {:adapter => "mysql"}, 0, state, &explainer) }
202
203
  sleep 0.02
203
204
  yield if block_given?
204
- sampler.notice_pop_frame "a"
205
+ sampler.notice_pop_frame(state, "a")
205
206
  end
206
207
 
207
208
  return sampler.last_sample
@@ -209,19 +210,20 @@ module TransactionSampleTestHelper
209
210
 
210
211
  def run_sample_trace(path='/path')
211
212
  sampler = nil
213
+ state = NewRelic::Agent::TransactionState.tl_get
212
214
 
213
215
  request = stub(:uri => path)
214
216
 
215
217
  in_transaction("Controller/sandwiches/index", :request => request) do
216
218
  sampler = NewRelic::Agent.instance.transaction_sampler
217
- sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'wheat'", {}, 0)
218
- sampler.notice_push_frame "ab"
219
- sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'white'", {}, 0)
219
+ sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'wheat'", {}, 0, state)
220
+ sampler.notice_push_frame(state, "ab")
221
+ sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'white'", {}, 0, state)
220
222
  yield sampler if block_given?
221
- sampler.notice_pop_frame "ab"
222
- sampler.notice_push_frame "lew"
223
- sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'french'", {}, 0)
224
- sampler.notice_pop_frame "lew"
223
+ sampler.notice_pop_frame(state, "ab")
224
+ sampler.notice_push_frame(state, "lew")
225
+ sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'french'", {}, 0, state)
226
+ sampler.notice_pop_frame(state, "lew")
225
227
  end
226
228
 
227
229
  return sampler.last_sample
@@ -20,12 +20,6 @@ module NewRelic::DeveloperModeHelper
20
20
  (!@detail_segment_count.nil? && @detail_segment_count > trace_row_display_limit) || @sample.sql_segments.length > trace_row_display_limit
21
21
  end
22
22
 
23
- # return the sample but post processed to strip out segments that normally don't show
24
- # up in production (after the first execution, at least) such as application code loading
25
- def stripped_sample(sample = @sample)
26
- sample.omit_segments_with('(Rails/Application Code Loading)|(Database/.*/.+ Columns)')
27
- end
28
-
29
23
  # return the highest level in the call stack for the trace that is not rails or
30
24
  # newrelic agent code
31
25
  def application_caller(trace)
@@ -62,40 +56,13 @@ module NewRelic::DeveloperModeHelper
62
56
  path
63
57
  end
64
58
 
65
- def url_for_source(trace_line)
66
- file, line = file_and_line(trace_line)
67
- return "#" if file.nil?
68
- begin
69
- file = Pathname.new(file).realpath
70
- rescue Errno::ENOENT
71
- # we hit this exception when Pathame.realpath fails for some reason; attempt a link to
72
- # the file without a real path. It may also fail, only when the user clicks on this specific
73
- # entry in the stack trace
74
- rescue
75
- # catch all other exceptions. We're going to create an invalid link below, but that's okay.
76
- end
77
- if NewRelic::Agent.config[:textmate]
78
- "txmt://open?url=file://#{file}&line=#{line}"
79
- else
80
- "show_source?file=#{file}&amp;line=#{line}&amp;anchor=selected_line"
81
- end
82
- end
83
-
84
59
  def dev_name(metric_name)
85
60
  NewRelic::MetricParser::MetricParser.parse(metric_name).developer_name
86
61
  end
87
62
 
88
63
  # write the metric label for a segment metric in the detail view
89
64
  def write_segment_label(segment)
90
- if source_available && segment[:backtrace] && (source_url = url_for_source(application_caller(segment[:backtrace])))
91
- link_to dev_name(segment.metric_name), source_url
92
- else
93
- dev_name(segment.metric_name)
94
- end
95
- end
96
-
97
- def source_available
98
- true
65
+ link_to_function(dev_name(segment.metric_name), "toggle_row_class($(this).closest('td').find('a')[0])")
99
66
  end
100
67
 
101
68
  # write the metric label for a segment metric in the summary table of metrics
@@ -104,14 +71,7 @@ module NewRelic::DeveloperModeHelper
104
71
  end
105
72
 
106
73
  def write_stack_trace_line(trace_line)
107
- link_to trace_line, url_for_source(trace_line)
108
- end
109
-
110
- # write a link to the source for a trace
111
- def link_to_source(trace)
112
- image_url = 'file/images/' + (NewRelic::Agent.config[:textmate] ? "textmate.png" : "file_icon.png")
113
-
114
- link_to "<img src=#{image_url} alt=\"View Source\" title=\"View Source\"/>", url_for_source(application_caller(trace))
74
+ trace_line
115
75
  end
116
76
 
117
77
  # print the formatted timestamp for a segment
@@ -171,7 +131,7 @@ module NewRelic::DeveloperModeHelper
171
131
  if depth > 0
172
132
  if !segment.called_segments.empty?
173
133
  row_class =segment_child_row_class(segment)
174
- link_to_function("<img src=\"#{collapsed_image_path}\" id=\"image_#{row_class}\" class_for_children=\"#{row_class}\" class=\"#{(!segment.called_segments.empty?) ? 'parent_segment_image' : 'child_segment_image'}\"", "toggle_row_class(this)")
134
+ link_to_function("<img src=\"#{collapsed_image_path}\" id=\"image_#{row_class}\" class_for_children=\"#{row_class}\" class=\"#{(!segment.called_segments.empty?) ? 'parent_segment_image' : 'child_segment_image'}\" />", "toggle_row_class(this)")
175
135
  end
176
136
  end
177
137
  end
@@ -29,7 +29,7 @@
29
29
  <span class="application_title">Developer Mode</span>
30
30
  </td>
31
31
  <td class="title_bar_right">
32
- Monitor your Rails Application in production. <%=link_to 'Learn more.', 'http://www.newrelic.com/dev-upgrade.html' %>
32
+ Monitor your Rails Application in production. <%=link_to 'Learn more.', 'http://www.newrelic.com' %>
33
33
  </td>
34
34
  </tr>
35
35
  </table>
@@ -42,7 +42,7 @@
42
42
  <img width="100%" height="4" src="/newrelic/file/images/blue_bar.gif" alt="spacer"/>
43
43
  <p>
44
44
  <a href="/newrelic">Home</a> | <a href="&#109;&#97;&#105;&#108;&#116;&#111;:&#x73;&#x75;&#x70;&#112;&#111;&#x72;&#116;&#x40;&#x6E;&#x65;&#119;&#114;&#x65;&#x6C;&#105;&#x63;&#x2E;&#99;&#x6F;&#109;?subject=&#70;&#101;&#x65;&#x64;&#x62;&#x61;&#x63;&#107;" title="">&#x46;&#x65;&#101;&#x64;&#98;&#97;&#x63;&#x6B;</a><br />
45
- Monitor your Rails Application in Production. <a href="http://www.newrelic.com/dev-upgrade.html">Learn more. &raquo;</a><br />
45
+ Monitor your Rails Application in Production. <a href="http://www.newrelic.com">Learn more. &raquo;</a><br />
46
46
  &copy; 2008 - <%= Time.now.strftime('%Y') %> New Relic. All rights reserved.</p>
47
47
  </div>
48
48
  </body>
@@ -1,10 +1,10 @@
1
1
  <% sample = object %>
2
2
  <tr class="<%= cycle('even_row', 'odd_row') %>">
3
3
  <td align=right nowrap=true>
4
- <%= Time.at(stripped_sample(sample).timestamp).strftime "%H:%M:%S" %>
4
+ <%= Time.at(sample.timestamp).strftime "%H:%M:%S" %>
5
5
  </td>
6
6
  <td align=right nowrap=true>
7
- <%= colorize(stripped_sample(sample).duration, 1, 2) %> ms
7
+ <%= colorize(sample.duration, 1, 2) %> ms
8
8
  </td>
9
9
  <td>
10
10
  <%= link_to "#{sample.params[:uri]}", "show_sample_summary?id=#{sample.sample_id}" %>
@@ -1,16 +1,16 @@
1
1
  <% segment = object %>
2
2
  <tr class='<%= cycle('even_row', 'odd_row') %>'>
3
3
  <td align=right><%= timestamp(segment) %></td>
4
- <td align=right><%= segment_duration_value(segment) %> </td>
5
- <td> <%= link_to_source(segment[:backtrace]) %> </td>
6
- <td align=left>
7
- <div class="sql_statement">
8
- <small>
9
- <% if segment[:sql] %>
10
- <%= line_wrap_sql(segment[:sql] ) %>
11
- <% else %>
12
- Non-sql query: <%= segment.metric_name %> <%= line_wrap_sql(segment[:key]) %>
13
- <% end %></small>
14
- </div>
4
+ <td align=right><%= segment_duration_value(segment) %> </td>
5
+ <td></td>
6
+ <td align=left>
7
+ <div class="sql_statement">
8
+ <small>
9
+ <% if segment[:sql] %>
10
+ <%= line_wrap_sql(segment[:sql] ) %>
11
+ <% else %>
12
+ Non-sql query: <%= segment.metric_name %> <%= line_wrap_sql(segment[:key]) %>
13
+ <% end %></small>
14
+ </div>
15
15
  </td>
16
16
  </tr>
@@ -21,32 +21,31 @@
21
21
  </table>
22
22
  </td>
23
23
  <td valign=top>
24
- <% if defined?(Rainbows) || defined?(Unicorn) || defined?(Passenger) %>
25
- <div class="flash">
26
- <p id="errorExplanation">
27
- We've noticed you're running a forking web server, like Rainbows, Unicorn, or Passenger. See Below</p><p> Developer mode may be unpredictable,
28
- since those servers run many processes and developer mode is entirely in the process.</p><p> We suggest you try Thin,
29
- Mongrel, or another single-process web server for development mode.</p><p>
30
- (You can ignore this message if you're sure that you're running only one process, and it's not being reaped when inactive.)
31
- </p>
32
- </div>
33
- <% end %>
34
-
24
+ <% if defined?(Rainbows) || defined?(Unicorn) || defined?(Passenger) %>
25
+ <div class="flash">
26
+ <p id="errorExplanation">
27
+ We've noticed you're running a forking web server, like Rainbows, Unicorn, or Passenger. See Below</p><p> Developer mode may be unpredictable,
28
+ since those servers run many processes and developer mode is entirely in the process.</p><p> We suggest you try Thin,
29
+ Mongrel, or another single-process web server for development mode.</p><p>
30
+ (You can ignore this message if you're sure that you're running only one process, and it's not being reaped when inactive.)
31
+ </p>
32
+ </div>
33
+ <% end %>
35
34
 
36
35
  <%= link_to_if @samples.size > 0, "Clear Transactions (#{@samples.size})", 'reset' %><br/>
37
36
  <%= link_to "List Threads", 'threads' %><br/>
38
- <% if NewRelic::Agent.config[:'profiling.available'] %>
39
- <p><b>Profiling available:</b>
40
- <% if NewRelic::Agent.config[:'profiling.enabled'] %>
37
+ <% if NewRelic::Agent.config[:'profiling.available'] %>
38
+ <p><b>Profiling available:</b>
39
+ <% if NewRelic::Rack::DeveloperMode.profiling_enabled? %>
41
40
  <%= link_to "Stop Profiling", 'profile?stop=true'%>
42
- <% else %>
41
+ <% else %>
43
42
  <%= link_to "Start Profiling", 'profile?start=true' %>
44
- <% end %>
45
- </p>
46
- <% else %>
47
- <p>You can use the ruby-prof gem to display profiles of your actions with Developer Mode. Just
48
- install the ruby-prof gem and restart your app.</p>
49
- <% end %>
43
+ <% end %>
44
+ </p>
45
+ <% else %>
46
+ <p>You can use the ruby-prof gem to display profiles of your actions with Developer Mode. Just
47
+ install the ruby-prof gem and restart your app.</p>
48
+ <% end %>
50
49
  <h3>Welcome</h3>
51
50
  <p>
52
51
  Welcome to <b>New Relic Developer Mode</b>. This Rails extension traces the performance activity
@@ -63,7 +62,7 @@
63
62
  </p>
64
63
  <p>
65
64
  Note, to increase the accuracy of our performance measurement, we automatically "strip out" any
66
- time spent in application code loading, which will not happen when your application runs in
65
+ time spent in application code loading, which will not happen when your application runs in
67
66
  production mode.
68
67
  </p>
69
68
  </td>
@@ -82,7 +82,8 @@ module DependencyDetection
82
82
  end
83
83
 
84
84
  def check_dependencies
85
- return false unless dependencies
85
+ return false unless allowed_by_config? && dependencies
86
+
86
87
  dependencies.all? do |dep|
87
88
  begin
88
89
  dep.call
@@ -97,17 +98,21 @@ module DependencyDetection
97
98
  @dependencies << Proc.new
98
99
  end
99
100
 
101
+ def allowed_by_config?
102
+ # If we don't have a name, can't check config so allow it
103
+ return true if self.name.nil?
104
+
105
+ key = "disable_#{self.name}".to_sym
106
+ if (::NewRelic::Agent.config[key] == true)
107
+ ::NewRelic::Agent.logger.debug("Not installing #{self.name} instrumentation because of configuration #{key}")
108
+ false
109
+ else
110
+ true
111
+ end
112
+ end
113
+
100
114
  def named(new_name)
101
115
  self.name = new_name
102
- depends_on do
103
- key = "disable_#{new_name}".to_sym
104
- if (::NewRelic::Agent.config[key] == true)
105
- ::NewRelic::Agent.logger.debug("Not installing #{new_name} instrumentation because of configuration #{key}")
106
- false
107
- else
108
- true
109
- end
110
- end
111
116
  end
112
117
 
113
118
  def executes
@@ -49,6 +49,8 @@ require 'new_relic/metric_parser/jsp'
49
49
  require 'new_relic/metric_parser/jsp_tag'
50
50
  require 'new_relic/metric_parser/mem_cache'
51
51
  require 'new_relic/metric_parser/metric_parser'
52
+ require 'new_relic/metric_parser/middleware'
53
+ require 'new_relic/metric_parser/nested'
52
54
  require 'new_relic/metric_parser/orm'
53
55
  require 'new_relic/metric_parser/other_transaction'
54
56
  require 'new_relic/metric_parser/servlet'
@@ -0,0 +1,34 @@
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/metric_parser'
6
+
7
+ module NewRelic
8
+ module MetricParser
9
+ class Middleware < MetricParser
10
+ ALL = 'Middleware/all'.freeze
11
+ RACK = 'Rack'.freeze
12
+
13
+ def ui_name(value_fn=nil,options={})
14
+ if metric_name == ALL
15
+ "Middleware"
16
+ else
17
+ "#{segments[2]}\##{segments[3]}"
18
+ end
19
+ end
20
+
21
+ def is_middleware?
22
+ true
23
+ end
24
+
25
+ def controller_name
26
+ segments[2]
27
+ end
28
+
29
+ def action_name
30
+ segments[3]
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,24 @@
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/metric_parser'
6
+
7
+ module NewRelic
8
+ module MetricParser
9
+ class Nested < Controller
10
+ def initialize(name)
11
+ name_without_prefix = name.gsub(/^Nested\//, '')
12
+ super(name_without_prefix)
13
+ end
14
+
15
+ def is_web_transaction?
16
+ false
17
+ end
18
+
19
+ def is_transaction?
20
+ false
21
+ end
22
+ end
23
+ end
24
+ end