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
@@ -12,7 +12,7 @@ module NewRelic
12
12
 
13
13
  def initialize(segments)
14
14
  summary = SummarySegment.new(segments.first)
15
- super summary.entry_timestamp, "Repeating pattern (#{segments.length} repeats)", nil
15
+ super summary.entry_timestamp, "Repeating pattern (#{segments.length} repeats)"
16
16
 
17
17
  summary.end_trace(segments.last.exit_timestamp)
18
18
 
@@ -12,14 +12,19 @@ module NewRelic
12
12
  # have a timestamp.
13
13
  attr_reader :exit_timestamp
14
14
  attr_reader :parent_segment
15
+
16
+ # This is only used from developer mode and rpm_site.
17
+ # No new clients should be added.
15
18
  attr_reader :segment_id
16
19
 
17
20
  attr_accessor :metric_name
18
21
 
19
- def initialize(timestamp, metric_name, segment_id)
22
+ UNKNOWN_SEGMENT_NAME = '<unknown>'.freeze
23
+
24
+ def initialize(timestamp, metric_name, segment_id=nil)
20
25
  @entry_timestamp = timestamp
21
- @metric_name = metric_name || '<unknown>'
22
- @segment_id = segment_id || object_id
26
+ @metric_name = metric_name || UNKNOWN_SEGMENT_NAME
27
+ @segment_id = segment_id || object_id
23
28
  end
24
29
 
25
30
  # sets the final timestamp on a segment to indicate the exit
@@ -55,6 +60,7 @@ module NewRelic
55
60
  def path_string
56
61
  "#{metric_name}[#{called_segments.collect {|segment| segment.path_string }.join('')}]"
57
62
  end
63
+
58
64
  def to_s_compact
59
65
  str = ""
60
66
  str << metric_name
@@ -63,6 +69,7 @@ module NewRelic
63
69
  end
64
70
  str
65
71
  end
72
+
66
73
  def to_debug_str(depth)
67
74
  tab = " " * depth
68
75
  s = tab.clone
@@ -155,8 +162,9 @@ module NewRelic
155
162
  summary.current_nest_count -= 1 if summary
156
163
  end
157
164
 
165
+ # This is only for use by developer mode
158
166
  def find_segment(id)
159
- return self if @segment_id == id
167
+ return self if segment_id == id
160
168
  called_segments.each do |segment|
161
169
  found = segment.find_segment(id)
162
170
  return found if found
@@ -8,7 +8,7 @@ module NewRelic
8
8
  class TransactionSample
9
9
  class SummarySegment < Segment
10
10
  def initialize(segment)
11
- super segment.entry_timestamp, segment.metric_name, nil
11
+ super segment.entry_timestamp, segment.metric_name
12
12
 
13
13
  add_segments segment.called_segments
14
14
 
@@ -11,8 +11,8 @@ module NewRelic
11
11
  end
12
12
 
13
13
  MAJOR = 3
14
- MINOR = 8
15
- TINY = 1
14
+ MINOR = 9
15
+ TINY = 0
16
16
 
17
17
  begin
18
18
  require File.join(File.dirname(__FILE__), 'build')
data/lib/newrelic_rpm.rb CHANGED
@@ -32,7 +32,7 @@ if defined?(Merb) && defined?(Merb::BootLoader)
32
32
  end
33
33
  end
34
34
  end
35
- elsif defined? Rails
35
+ elsif defined?(Rails::VERSION)
36
36
  if Rails::VERSION::MAJOR.to_i >= 3
37
37
  module NewRelic
38
38
  class Railtie < Rails::Railtie
@@ -35,8 +35,9 @@ module Sequel
35
35
 
36
36
 
37
37
  # Instrument all queries that go through #execute_query.
38
- def log_yield( sql, args=nil )
39
- return super unless NewRelic::Agent.is_execution_traced?
38
+ def log_yield(sql, args=nil) #THREAD_LOCAL_ACCESS
39
+ state = NewRelic::Agent::TransactionState.tl_get
40
+ return super unless state.is_execution_traced?
40
41
 
41
42
  t0 = Time.now
42
43
  rval = super
@@ -44,8 +45,8 @@ module Sequel
44
45
 
45
46
  begin
46
47
  duration = t1 - t0
47
- record_metrics( sql, args, duration )
48
- notice_sql( sql, args, t0, t1 )
48
+ record_metrics(sql, args, duration)
49
+ notice_sql(state, sql, args, t0, t1)
49
50
  rescue => err
50
51
  NewRelic::Agent.logger.debug "while recording metrics for Sequel", err
51
52
  end
@@ -55,16 +56,14 @@ module Sequel
55
56
 
56
57
  # Record metrics for the specified +sql+ and +args+ using the specified
57
58
  # +duration+.
58
- def record_metrics( sql, args, duration)
59
- primary_metric = primary_metric_for( sql, args )
59
+ def record_metrics(sql, args, duration) #THREAD_LOCAL_ACCESS
60
+ primary_metric = primary_metric_for(sql, args)
60
61
  engine = NewRelic::Agent.instance.stats_engine
61
62
 
62
- engine.record_metrics( primary_metric, duration, :scoped => true )
63
+ metrics = rollup_metrics_for(primary_metric)
64
+ metrics << remote_service_metric(*self.opts.values_at(:adapter, :host)) if self.opts.key?(:adapter)
63
65
 
64
- metrics = rollup_metrics_for( primary_metric )
65
- metrics << remote_service_metric( *self.opts.values_at(:adapter, :host) ) if self.opts.key?(:adapter)
66
-
67
- engine.record_metrics( metrics, duration, :scoped => false )
66
+ engine.tl_record_scoped_and_unscoped_metrics(primary_metric, metrics, duration)
68
67
  end
69
68
 
70
69
  THREAD_SAFE_CONNECTION_POOL_CLASSES = [
@@ -73,13 +72,14 @@ module Sequel
73
72
 
74
73
  # Record the given +sql+ within a new frame, using the given +start+ and
75
74
  # +finish+ times.
76
- def notice_sql( sql, args, start, finish )
77
- metric = primary_metric_for( sql, args )
75
+ def notice_sql(state, sql, args, start, finish)
76
+ metric = primary_metric_for(sql, args)
78
77
  agent = NewRelic::Agent.instance
79
78
  duration = finish - start
79
+ stack = state.traced_method_stack
80
80
 
81
81
  begin
82
- frame = NewRelic::Agent::TracedMethodStack.push_frame( :sequel, start )
82
+ frame = stack.push_frame(state, :sequel, start)
83
83
  explainer = Proc.new do |*|
84
84
  if THREAD_SAFE_CONNECTION_POOL_CLASSES.include?(self.pool.class)
85
85
  self[ sql ].explain
@@ -88,22 +88,22 @@ module Sequel
88
88
  nil
89
89
  end
90
90
  end
91
- agent.transaction_sampler.notice_sql( sql, self.opts, duration, &explainer )
92
- agent.sql_sampler.notice_sql( sql, metric, self.opts, duration, &explainer )
91
+ agent.transaction_sampler.notice_sql(sql, self.opts, duration, state, &explainer)
92
+ agent.sql_sampler.notice_sql(sql, metric, self.opts, duration, state, &explainer)
93
93
  ensure
94
- NewRelic::Agent::TracedMethodStack.pop_frame( frame, metric, finish )
94
+ stack.pop_frame(state, frame, metric, finish)
95
95
  end
96
96
  end
97
97
 
98
98
 
99
99
  # Derive a primary database metric for the specified +sql+.
100
- def primary_metric_for( sql, _ )
100
+ def primary_metric_for(sql, _)
101
101
  return metric_for_sql(NewRelic::Helper.correctly_encoded(sql))
102
102
  end
103
103
 
104
104
  end # module NewRelicInstrumentation
105
105
 
106
106
  NewRelic::Agent.logger.debug "Registering the :newrelic_instrumentation extension."
107
- Database.register_extension( :newrelic_instrumentation, NewRelicInstrumentation )
107
+ Database.register_extension(:newrelic_instrumentation, NewRelicInstrumentation)
108
108
 
109
109
  end # module Sequel
data/lib/tasks/tests.rake CHANGED
@@ -4,7 +4,25 @@ rescue LoadError => e
4
4
  end
5
5
 
6
6
  if defined? Rake::TestTask
7
- namespace :test do
7
+ namespace :test do |t|
8
+ def look_for_seed(tasks)
9
+ matches = tasks.map { |t| /(seed=.*?)[,\]]/.match(t) }.compact
10
+ if matches.any?
11
+ matches.first[1]
12
+ else
13
+ nil
14
+ end
15
+ end
16
+
17
+ tasks = Rake.application.top_level_tasks
18
+ ENV["TESTOPTS"] ||= ""
19
+ if tasks.any? { |t| t.include?("verbose")}
20
+ ENV["TESTOPTS"] += " -v"
21
+ end
22
+ if seed = look_for_seed(tasks)
23
+ ENV["TESTOPTS"] += " --" + seed
24
+ end
25
+
8
26
  agent_home = File.expand_path(File.join(File.dirname(__FILE__),'..','..'))
9
27
 
10
28
  Rake::TestTask.new(:newrelic) do |t|
@@ -13,5 +31,6 @@ if defined? Rake::TestTask
13
31
  t.pattern = "#{agent_home}/test/new_relic/**/*_test.rb"
14
32
  t.verbose = true
15
33
  end
34
+
16
35
  end
17
36
  end
@@ -2,20 +2,16 @@
2
2
  <table>
3
3
  <thead>
4
4
  <th>Name</th>
5
- <% unless suppress_versions %>
6
5
  <th>Supported</th>
7
6
  <th>Deprecated</th>
8
7
  <th>Experimental</th>
9
- <% end %>
10
8
  </thead>
11
9
  <% for version in versions %>
12
10
  <tr>
13
11
  <td><b><%= version.name %></b></td>
14
- <% unless suppress_versions %>
15
12
  <td><%= version_list(version.supported) %></td>
16
13
  <td><%= version_list(version.deprecated) %></td>
17
14
  <td><%= version_list(version.experimental) %></td>
18
- <% end %>
19
15
  </tr>
20
16
  <% if version.notes %>
21
17
  <tr>
@@ -12,7 +12,8 @@ namespace :newrelic do
12
12
 
13
13
  def versions_for_type(type)
14
14
  NewRelic::Agent::SUPPORTED_VERSIONS.
15
- select {|_,v| v[:type] == type}.
15
+ select {|key, values| values[:type] == type}.
16
+ sort_by {|key, values| (values[:name] || key).to_s }.
16
17
  map do |key,values|
17
18
  VersionStruct.new(
18
19
  values[:name] || key,
@@ -30,7 +31,7 @@ namespace :newrelic do
30
31
  ERB.new(template)
31
32
  end
32
33
 
33
- def write_versions(title, type, erb, suppress_versions = false)
34
+ def write_versions(title, type, erb)
34
35
  anchor = title.downcase.gsub(" ", "_")
35
36
  versions = versions_for_type(type)
36
37
  puts erb.result(binding).gsub(/^ *$/, '')
@@ -47,6 +48,6 @@ namespace :newrelic do
47
48
  write_versions("Database", :database, erb)
48
49
  write_versions("Background Jobs", :background, erb)
49
50
  write_versions("HTTP Clients", :http, erb)
50
- write_versions("Other", :other, erb, true)
51
+ write_versions("Other", :other, erb)
51
52
  end
52
53
  end
data/newrelic.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  #
2
- # This file configures the New Relic Agent. New Relic monitors
3
- # Ruby, Java, .NET, PHP, and Python applications with deep visibility and low overhead.
4
- # For more information, visit www.newrelic.com.
2
+ # This file configures the New Relic Agent. New Relic monitors Ruby, Java,
3
+ # .NET, PHP, Python and Node applications with deep visibility and low
4
+ # overhead. For more information, visit www.newrelic.com.
5
5
  #
6
6
  # Generated <%= Time.now.strftime('%B %d, %Y') %>, for version <%= NewRelic::VERSION::STRING %>
7
7
  #
@@ -160,11 +160,6 @@ common: &default_settings
160
160
  # product levels.
161
161
  enabled: true
162
162
 
163
- # Rails Only - tells error collector whether or not to capture a
164
- # source snippet around the place of the error when errors are View
165
- # related.
166
- capture_source: true
167
-
168
163
  # To stop specific errors from reporting to New Relic, set this property
169
164
  # to comma-separated values. Default is to ignore routing errors,
170
165
  # which are how 404's get triggered.
@@ -197,10 +192,7 @@ development:
197
192
  # executed since starting the mongrel.
198
193
  # NOTE: There is substantial overhead when running in developer mode.
199
194
  # Do not use for production or load testing.
200
- developer_mode: false
201
-
202
- # Enable textmate links
203
- # textmate: true
195
+ developer_mode: true
204
196
 
205
197
  test:
206
198
  <<: *default_settings
data/newrelic_rpm.gemspec CHANGED
@@ -46,7 +46,7 @@ EOS
46
46
  s.add_development_dependency 'mocha', '~> 0.13.0'
47
47
  s.add_development_dependency 'yard'
48
48
  s.add_development_dependency 'rails', '~> 3.2.13'
49
- s.add_development_dependency 'pry'
49
+ s.add_development_dependency 'pry', '~> 0.9.12'
50
50
  # s.add_development_dependency 'pry-nav'
51
51
  s.add_development_dependency 'guard', '~> 1.8.3' # Guard 2.0 is Ruby 1.9 only
52
52
  s.add_development_dependency 'guard-minitest'
data/test/agent_helper.rb CHANGED
@@ -28,7 +28,7 @@ end
28
28
 
29
29
  def assert_has_error(error_class)
30
30
  assert \
31
- NewRelic::Agent.instance.error_collector.errors.find {|e| e.exception_class_constant == error_class} != nil, \
31
+ NewRelic::Agent.instance.error_collector.errors.find {|e| e.exception_class_name == error_class.name} != nil, \
32
32
  "Didn't find error of class #{error_class}"
33
33
  end
34
34
 
@@ -90,6 +90,32 @@ def _normalize_metric_expectations(expectations)
90
90
  end
91
91
  end
92
92
 
93
+ def dump_stats(stats)
94
+ str = " Call count: #{stats.call_count}\n"
95
+ str << " Total call time: #{stats.total_call_time}\n"
96
+ str << " Total exclusive time: #{stats.total_exclusive_time}\n"
97
+ str << " Min call time: #{stats.min_call_time}\n"
98
+ str << " Max call time: #{stats.max_call_time}\n"
99
+ str << " Sum of squares: #{stats.sum_of_squares}\n"
100
+ str << " Apdex S: #{stats.apdex_s}\n"
101
+ str << " Apdex T: #{stats.apdex_t}\n"
102
+ str << " Apdex F: #{stats.apdex_f}\n"
103
+ str
104
+ end
105
+
106
+ def assert_stats_has_values(stats, expected_spec, expected_attrs)
107
+ expected_attrs.each do |attr, expected_value|
108
+ actual_value = stats.send(attr)
109
+ if attr == :call_count
110
+ assert_equal(expected_value, actual_value,
111
+ "Expected #{attr} for #{expected_spec} to be #{expected_value}, got #{actual_value}.\nActual stats:\n#{dump_stats(stats)}")
112
+ else
113
+ assert_in_delta(expected_value, actual_value, 0.0001,
114
+ "Expected #{attr} for #{expected_spec} to be ~#{expected_value}, got #{actual_value}.\nActual stats:\n#{dump_stats(stats)}")
115
+ end
116
+ end
117
+ end
118
+
93
119
  def assert_metrics_recorded(expected)
94
120
  expected = _normalize_metric_expectations(expected)
95
121
  expected.each do |specish, expected_attrs|
@@ -99,39 +125,47 @@ def assert_metrics_recorded(expected)
99
125
  all_specs = NewRelic::Agent.instance.stats_engine.metric_specs.sort
100
126
  matches = all_specs.select { |spec| spec.name == expected_spec.name }
101
127
  matches.map! { |m| " #{m.inspect}" }
128
+
102
129
  msg = "Did not find stats for spec #{expected_spec.inspect}."
103
130
  msg += "\nDid find specs: [\n#{matches.join(",\n")}\n]" unless matches.empty?
104
-
105
- msg += "\nAll specs in there were: [\n#{all_specs.map do |s|
106
- " #{s.name} (#{s.scope.empty? ? '<unscoped>' : s.scope})"
107
- end.join(",\n")}\n]"
131
+ msg += "\nAll specs in there were: #{format_metric_spec_list(all_specs)}"
108
132
 
109
133
  assert(actual_stats, msg)
110
134
  end
111
- expected_attrs.each do |attr, expected_value|
112
- actual_value = actual_stats.send(attr)
113
- if attr == :call_count
114
- assert_equal(expected_value, actual_value,
115
- "Expected #{attr} for #{expected_spec} to be #{expected_value}, got #{actual_value}")
116
- else
117
- assert_in_delta(expected_value, actual_value, 0.0001,
118
- "Expected #{attr} for #{expected_spec} to be ~#{expected_value}, got #{actual_value}")
119
- end
120
- end
135
+ assert_stats_has_values(actual_stats, expected_spec, expected_attrs)
121
136
  end
122
137
  end
123
138
 
139
+ # Use this to assert that *only* the given set of metrics has been recorded.
140
+ #
141
+ # If you want to scope the search for unexpected metrics to a particular
142
+ # namespace (e.g. metrics matching 'Controller/'), pass a Regex for the
143
+ # :filter option. Only metrics matching the regex will be searched when looking
144
+ # for unexpected metrics.
145
+ #
146
+ # If you want to *allow* unexpected metrics matching certain patterns, use
147
+ # the :ignore_filter option. This will allow you to specify a Regex that
148
+ # whitelists broad swathes of metric territory (e.g. 'Supportability/').
149
+ #
124
150
  def assert_metrics_recorded_exclusive(expected, options={})
125
151
  expected = _normalize_metric_expectations(expected)
126
152
  assert_metrics_recorded(expected)
127
- recorded_metrics = NewRelic::Agent.instance.stats_engine.metrics
153
+
154
+ recorded_metrics = NewRelic::Agent.instance.stats_engine.metric_specs
155
+
128
156
  if options[:filter]
129
- recorded_metrics = recorded_metrics.select { |m| m.match(options[:filter]) }
157
+ recorded_metrics = recorded_metrics.select { |m| m.name.match(options[:filter]) }
130
158
  end
131
- expected_metrics = expected.keys.map { |s| metric_spec_from_specish(s).to_s }
132
- unexpected_metrics = recorded_metrics.select { |m| m !~ /GC\/Transaction/ }
133
- unexpected_metrics -= expected_metrics
134
- assert_equal(0, unexpected_metrics.size, "Found unexpected metrics: [#{unexpected_metrics.join(', ')}]")
159
+ if options[:ignore_filter]
160
+ recorded_metrics.reject! { |m| m.name.match(options[:ignore_filter]) }
161
+ end
162
+
163
+ expected_metrics = expected.keys.map { |s| metric_spec_from_specish(s) }
164
+
165
+ unexpected_metrics = recorded_metrics - expected_metrics
166
+ unexpected_metrics.reject! { |m| m.name =~ /GC\/Transaction/ }
167
+
168
+ assert_equal(0, unexpected_metrics.size, "Found unexpected metrics: #{format_metric_spec_list(unexpected_metrics)}")
135
169
  end
136
170
 
137
171
  def assert_metrics_not_recorded(not_expected)
@@ -143,7 +177,14 @@ def assert_metrics_not_recorded(not_expected)
143
177
  found_but_not_expected << spec
144
178
  end
145
179
  end
146
- assert_equal([], found_but_not_expected, "Found unexpected metrics: [#{found_but_not_expected.join(', ')}]")
180
+ assert_equal([], found_but_not_expected, "Found unexpected metrics: #{format_metric_spec_list(found_but_not_expected)}")
181
+ end
182
+
183
+ def format_metric_spec_list(specs)
184
+ spec_strings = specs.map do |spec|
185
+ "#{spec.name} (#{spec.scope.empty? ? '<unscoped>' : spec.scope})"
186
+ end
187
+ "[\n #{spec_strings.join(",\n ")}\n]"
147
188
  end
148
189
 
149
190
  def assert_truthy(expected, msg = nil)
@@ -167,45 +208,46 @@ unless defined?(refute)
167
208
  end
168
209
 
169
210
  # Mock up a transaction for testing purposes, optionally specifying a name and
170
- # transaction type. The given block will be executed within the context of the
211
+ # transaction category. The given block will be executed within the context of the
171
212
  # dummy transaction.
172
213
  #
173
214
  # Examples:
174
215
  #
175
- # With default name ('dummy') and type (:other):
216
+ # With default name ('dummy') and category (:other):
176
217
  # in_transaction { ... }
177
218
  #
178
- # With an explicit transaction name and default type:
219
+ # With an explicit transaction name and default category:
179
220
  # in_transaction('foobar') { ... }
180
221
  #
181
- # With default name and explicit type:
182
- # in_transaction(:type => :controller) { ... }
222
+ # With default name and explicit category:
223
+ # in_transaction(:category => :controller) { ... }
183
224
  #
184
- # With a transaction name plus type:
185
- # in_transaction('foobar', :type => :controller) { ... }
225
+ # With a transaction name plus category:
226
+ # in_transaction('foobar', :category => :controller) { ... }
186
227
  #
187
228
  def in_transaction(*args)
188
229
  opts = (args.last && args.last.is_a?(Hash)) ? args.pop : {}
189
230
  opts[:transaction_name] = args.first || 'dummy'
190
- transaction_type = (opts && opts.delete(:type)) || :other
231
+ category = (opts && opts.delete(:category)) || :other
232
+ state = NewRelic::Agent::TransactionState.tl_get
191
233
 
192
- NewRelic::Agent::Transaction.start(transaction_type, opts)
234
+ NewRelic::Agent::Transaction.start(state, category, opts)
193
235
 
194
236
  val = nil
195
237
 
196
238
  begin
197
- val = yield NewRelic::Agent::Transaction.current
239
+ val = yield state.current_transaction
198
240
  ensure
199
- NewRelic::Agent::Transaction.stop()
241
+ NewRelic::Agent::Transaction.stop(state)
200
242
  end
201
243
 
202
244
  val
203
245
  end
204
246
 
205
- # Convenience wrapper around in_transaction that sets the type so that it
247
+ # Convenience wrapper around in_transaction that sets the category so that it
206
248
  # looks like we are in a web transaction
207
249
  def in_web_transaction(name='dummy')
208
- in_transaction(name, :type => :controller) do
250
+ in_transaction(name, :category => :controller) do
209
251
  yield
210
252
  end
211
253
  end
@@ -214,7 +256,7 @@ def find_last_transaction_segment(transaction_sample=nil)
214
256
  if transaction_sample
215
257
  root_segment = transaction_sample.root_segment
216
258
  else
217
- builder = NewRelic::Agent.agent.transaction_sampler.builder
259
+ builder = NewRelic::Agent.agent.transaction_sampler.tl_builder
218
260
  root_segment = builder.current_segment
219
261
  end
220
262
 
@@ -224,15 +266,49 @@ def find_last_transaction_segment(transaction_sample=nil)
224
266
  return last_segment
225
267
  end
226
268
 
227
- def find_segment_by_name(transaction_sample, name)
228
- first_segment = nil
229
- transaction_sample.root_segment.each_segment do |s|
230
- if s.metric_name == name
231
- first_segment = s
232
- break
269
+ def collect_segment_names(transaction_sample)
270
+ names = []
271
+
272
+ transaction_sample.root_segment.each_segment do |segment|
273
+ names << segment.metric_name
274
+ end
275
+
276
+ names
277
+ end
278
+
279
+ def find_segment_with_name(transaction_sample, name)
280
+ transaction_sample.root_segment.each_segment do |segment|
281
+ if segment.metric_name == name
282
+ return segment
283
+ end
284
+ end
285
+
286
+ nil
287
+ end
288
+
289
+ def find_segment_with_name_matching(transaction_sample, regex)
290
+ transaction_sample.root_segment.each_segment do |segment|
291
+ if segment.metric_name.match regex
292
+ return segment
233
293
  end
234
294
  end
235
- first_segment
295
+
296
+ nil
297
+ end
298
+
299
+ def find_all_segments_with_name_matching(transaction_sample, regexes)
300
+ regexes = [regexes].flatten
301
+ matching_segments = []
302
+
303
+ transaction_sample.root_segment.each_segment do |segment|
304
+ regexes.each do |regex|
305
+ if segment.metric_name.match regex
306
+ matching_segments << segment
307
+ end
308
+ end
309
+ end
310
+
311
+ matching_segments
236
312
  end
237
313
 
238
314
  def with_config(config_hash, opts={})
@@ -242,7 +318,7 @@ def with_config(config_hash, opts={})
242
318
  else
243
319
  config = NewRelic::Agent::Configuration::DottedHash.new(config_hash)
244
320
  end
245
- NewRelic::Agent.config.apply_config(config, opts[:level])
321
+ NewRelic::Agent.config.add_config_for_testing(config, opts[:level])
246
322
  begin
247
323
  yield
248
324
  ensure
@@ -355,3 +431,29 @@ def with_array_logger(level=:info)
355
431
  ensure
356
432
  NewRelic::Agent.logger = orig_logger
357
433
  end
434
+
435
+ def with_environment(env)
436
+ old_env = {}
437
+ env.each do |key, val|
438
+ old_env[key] = ENV[key]
439
+ ENV[key] = val.to_s
440
+ end
441
+ begin
442
+ yield
443
+ ensure
444
+ old_env.each { |key, old_val| ENV[key] = old_val }
445
+ end
446
+ end
447
+
448
+ def with_ignore_error_filter(filter, &blk)
449
+ original_filter = NewRelic::Agent.ignore_error_filter
450
+ NewRelic::Agent.ignore_error_filter(&filter)
451
+
452
+ yield
453
+ ensure
454
+ if original_filter.nil?
455
+ NewRelic::Agent.instance.error_collector.clear_ignore_error_filter
456
+ else
457
+ NewRelic::Agent.ignore_error_filter(&original_filter)
458
+ end
459
+ end