wd_newrelic_rpm 3.3.4.1 → 3.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (290) hide show
  1. data/.gitignore +20 -0
  2. data/.project +23 -0
  3. data/.travis.yml +9 -0
  4. data/CHANGELOG +317 -39
  5. data/GUIDELINES_FOR_CONTRIBUTING.md +76 -0
  6. data/Gemfile +16 -0
  7. data/LICENSE +1 -1
  8. data/{README.rdoc → README.md} +71 -55
  9. data/Rakefile +62 -0
  10. data/bin/mongrel_rpm +1 -1
  11. data/config.dot +290 -0
  12. data/config/database.yml +5 -0
  13. data/init.rb +31 -0
  14. data/lib/new_relic/agent.rb +31 -60
  15. data/lib/new_relic/agent/agent.rb +277 -502
  16. data/lib/new_relic/agent/agent_logger.rb +165 -0
  17. data/lib/new_relic/agent/audit_logger.rb +72 -0
  18. data/lib/new_relic/agent/beacon_configuration.rb +36 -50
  19. data/lib/new_relic/agent/browser_monitoring.rb +114 -61
  20. data/lib/new_relic/agent/busy_calculator.rb +14 -6
  21. data/lib/new_relic/agent/configuration.rb +74 -0
  22. data/lib/new_relic/agent/configuration/defaults.rb +126 -0
  23. data/lib/new_relic/agent/configuration/environment_source.rb +49 -0
  24. data/lib/new_relic/agent/configuration/manager.rb +136 -0
  25. data/lib/new_relic/agent/configuration/mask_defaults.rb +10 -0
  26. data/lib/new_relic/agent/configuration/server_source.rb +27 -0
  27. data/lib/new_relic/agent/configuration/yaml_source.rb +63 -0
  28. data/lib/new_relic/agent/cross_process_monitoring.rb +43 -0
  29. data/lib/new_relic/agent/database.rb +39 -26
  30. data/lib/new_relic/agent/error_collector.rb +48 -49
  31. data/lib/new_relic/agent/instrumentation/active_merchant.rb +1 -1
  32. data/lib/new_relic/agent/instrumentation/active_record.rb +4 -7
  33. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +1 -1
  34. data/lib/new_relic/agent/instrumentation/authlogic.rb +1 -1
  35. data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +41 -0
  36. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +35 -12
  37. data/lib/new_relic/agent/instrumentation/data_mapper.rb +4 -12
  38. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +2 -2
  39. data/lib/new_relic/agent/instrumentation/memcache.rb +6 -6
  40. data/lib/new_relic/agent/instrumentation/merb/controller.rb +1 -1
  41. data/lib/new_relic/agent/instrumentation/merb/errors.rb +1 -1
  42. data/lib/new_relic/agent/instrumentation/metric_frame.rb +4 -14
  43. data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +1 -1
  44. data/lib/new_relic/agent/instrumentation/net.rb +1 -1
  45. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +6 -20
  46. data/lib/new_relic/agent/instrumentation/queue_time.rb +2 -2
  47. data/lib/new_relic/agent/instrumentation/rack.rb +1 -1
  48. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +7 -7
  49. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +1 -1
  50. data/lib/new_relic/agent/instrumentation/rails/errors.rb +1 -1
  51. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +5 -5
  52. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +6 -2
  53. data/lib/new_relic/agent/instrumentation/resque.rb +81 -0
  54. data/lib/new_relic/agent/instrumentation/sinatra.rb +21 -10
  55. data/lib/new_relic/agent/instrumentation/sunspot.rb +1 -1
  56. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +5 -4
  57. data/lib/new_relic/agent/method_tracer.rb +11 -9
  58. data/lib/new_relic/agent/new_relic_service.rb +379 -0
  59. data/lib/new_relic/agent/pipe_channel_manager.rb +175 -0
  60. data/lib/new_relic/agent/pipe_service.rb +58 -0
  61. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +86 -0
  62. data/lib/new_relic/agent/samplers/memory_sampler.rb +6 -8
  63. data/lib/new_relic/agent/sql_sampler.rb +31 -74
  64. data/lib/new_relic/agent/stats_engine.rb +0 -5
  65. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +40 -24
  66. data/lib/new_relic/agent/stats_engine/metric_stats.rb +89 -14
  67. data/lib/new_relic/agent/stats_engine/samplers.rb +9 -7
  68. data/lib/new_relic/agent/stats_engine/transactions.rb +20 -12
  69. data/lib/new_relic/agent/thread.rb +32 -0
  70. data/lib/new_relic/agent/thread_profiler.rb +306 -0
  71. data/lib/new_relic/agent/transaction_info.rb +24 -4
  72. data/lib/new_relic/agent/transaction_sample_builder.rb +12 -13
  73. data/lib/new_relic/agent/transaction_sampler.rb +49 -65
  74. data/lib/new_relic/agent/worker_loop.rb +31 -25
  75. data/lib/new_relic/collection_helper.rb +1 -1
  76. data/lib/new_relic/commands/deployments.rb +19 -10
  77. data/lib/new_relic/control.rb +1 -3
  78. data/lib/new_relic/control/class_methods.rb +10 -5
  79. data/lib/new_relic/control/frameworks/merb.rb +0 -6
  80. data/lib/new_relic/control/frameworks/rails.rb +30 -45
  81. data/lib/new_relic/control/frameworks/rails3.rb +23 -18
  82. data/lib/new_relic/control/frameworks/rails4.rb +23 -0
  83. data/lib/new_relic/control/frameworks/ruby.rb +2 -23
  84. data/lib/new_relic/control/instance_methods.rb +35 -73
  85. data/lib/new_relic/control/instrumentation.rb +7 -12
  86. data/lib/new_relic/control/server_methods.rb +17 -19
  87. data/lib/new_relic/delayed_job_injection.rb +2 -2
  88. data/lib/new_relic/helper.rb +34 -0
  89. data/lib/new_relic/language_support.rb +56 -37
  90. data/lib/new_relic/local_environment.rb +32 -67
  91. data/lib/new_relic/metric_data.rb +10 -2
  92. data/lib/new_relic/metric_spec.rb +7 -3
  93. data/lib/new_relic/noticed_error.rb +32 -9
  94. data/lib/new_relic/rack.rb +4 -0
  95. data/lib/new_relic/rack/browser_monitoring.rb +34 -25
  96. data/lib/new_relic/rack/developer_mode.rb +3 -0
  97. data/lib/new_relic/rack/error_collector.rb +56 -0
  98. data/lib/new_relic/stats.rb +9 -7
  99. data/lib/new_relic/transaction_sample.rb +19 -18
  100. data/lib/new_relic/transaction_sample/segment.rb +13 -15
  101. data/lib/new_relic/version.rb +19 -3
  102. data/lib/newrelic_rpm.rb +1 -1
  103. data/lib/tasks/tests.rake +6 -8
  104. data/newrelic.yml +15 -32
  105. data/newrelic_rpm.gemspec +224 -43
  106. data/newrelic_rpm.gemspec.erb +54 -0
  107. data/test/config/newrelic.yml +4 -3
  108. data/test/config/test_control.rb +18 -18
  109. data/test/fixtures/gemspec_no_build.rb +442 -0
  110. data/test/fixtures/gemspec_with_build.rb +442 -0
  111. data/test/fixtures/gemspec_with_build_and_stage.rb +442 -0
  112. data/test/intentional_fail.rb +10 -0
  113. data/test/multiverse/.gitignore +10 -0
  114. data/test/multiverse/README.md +85 -0
  115. data/test/multiverse/lib/multiverse/color.rb +13 -0
  116. data/test/multiverse/lib/multiverse/envfile.rb +66 -0
  117. data/test/multiverse/lib/multiverse/environment.rb +16 -0
  118. data/test/multiverse/lib/multiverse/output_collector.rb +29 -0
  119. data/test/multiverse/lib/multiverse/runner.rb +44 -0
  120. data/test/multiverse/lib/multiverse/suite.rb +162 -0
  121. data/test/multiverse/script/run_one +3 -0
  122. data/test/multiverse/script/runner +9 -0
  123. data/test/multiverse/suites/active_record/Envfile +13 -0
  124. data/test/multiverse/suites/active_record/ar_method_aliasing.rb +94 -0
  125. data/test/multiverse/suites/active_record/config/newrelic.yml +22 -0
  126. data/test/multiverse/suites/active_record/encoding_test.rb +26 -0
  127. data/test/multiverse/suites/agent_only/Envfile +4 -0
  128. data/test/multiverse/suites/agent_only/audit_log_test.rb +99 -0
  129. data/test/multiverse/suites/agent_only/config/newrelic.yml +22 -0
  130. data/test/multiverse/suites/agent_only/http_response_code_test.rb +53 -0
  131. data/test/multiverse/suites/agent_only/marshaling_test.rb +109 -0
  132. data/test/multiverse/suites/agent_only/method_visibility_test.rb +98 -0
  133. data/test/multiverse/suites/agent_only/pipe_manager_test.rb +33 -0
  134. data/test/multiverse/suites/agent_only/service_timeout_test.rb +29 -0
  135. data/test/multiverse/suites/agent_only/test_trace_method_with_punctuation.rb +30 -0
  136. data/test/multiverse/suites/agent_only/test_trace_transaction_with_punctuation.rb +32 -0
  137. data/test/multiverse/suites/agent_only/thread_profiling_test.rb +80 -0
  138. data/test/multiverse/suites/config_file_loading/Envfile +7 -0
  139. data/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +106 -0
  140. data/test/multiverse/suites/datamapper/Envfile +8 -0
  141. data/test/multiverse/suites/datamapper/config/newrelic.yml +22 -0
  142. data/test/multiverse/suites/datamapper/encoding_test.rb +36 -0
  143. data/test/multiverse/suites/logging/Envfile +4 -0
  144. data/test/multiverse/suites/logging/config/newrelic.yml +22 -0
  145. data/test/multiverse/suites/logging/logging_test.rb +143 -0
  146. data/test/multiverse/suites/monitor_mode_false/Envfile +2 -0
  147. data/test/multiverse/suites/monitor_mode_false/config/newrelic.yml +25 -0
  148. data/test/multiverse/suites/monitor_mode_false/no_dns_resolv.rb +29 -0
  149. data/test/multiverse/suites/no_load/Envfile +2 -0
  150. data/test/multiverse/suites/no_load/config/newrelic.yml +22 -0
  151. data/test/multiverse/suites/no_load/start_up_test.rb +14 -0
  152. data/test/multiverse/suites/rails_3_error_tracing/Envfile +15 -0
  153. data/test/multiverse/suites/rails_3_error_tracing/config/newrelic.yml +165 -0
  154. data/test/multiverse/suites/rails_3_error_tracing/error_tracing_test.rb +236 -0
  155. data/test/multiverse/suites/rails_3_gc/Envfile +8 -0
  156. data/test/multiverse/suites/rails_3_gc/config/newrelic.yml +167 -0
  157. data/test/multiverse/suites/rails_3_gc/instrumentation_test.rb +92 -0
  158. data/test/multiverse/suites/rails_3_queue_time/Envfile +15 -0
  159. data/test/multiverse/suites/rails_3_queue_time/config/newrelic.yml +165 -0
  160. data/test/multiverse/suites/rails_3_queue_time/queue_time_test.rb +75 -0
  161. data/test/multiverse/suites/rails_3_views/.gitignore +3 -0
  162. data/test/multiverse/suites/rails_3_views/Envfile +16 -0
  163. data/test/multiverse/suites/rails_3_views/app/views/foos/_foo.html.haml +1 -0
  164. data/test/multiverse/suites/rails_3_views/app/views/test/_a_partial.html.erb +1 -0
  165. data/test/multiverse/suites/rails_3_views/app/views/test/_mid_partial.html.erb +1 -0
  166. data/test/multiverse/suites/rails_3_views/app/views/test/_top_partial.html.erb +3 -0
  167. data/test/multiverse/suites/rails_3_views/app/views/test/deep_partial.html.erb +3 -0
  168. data/test/multiverse/suites/rails_3_views/app/views/test/haml_view.html.haml +6 -0
  169. data/test/multiverse/suites/rails_3_views/app/views/test/index.html.erb +4 -0
  170. data/test/multiverse/suites/rails_3_views/config/newrelic.yml +164 -0
  171. data/test/multiverse/suites/rails_3_views/view_instrumentation_test.rb +245 -0
  172. data/test/multiverse/suites/resque/Envfile +21 -0
  173. data/test/multiverse/suites/resque/config/newrelic.yml +22 -0
  174. data/test/multiverse/suites/resque/dump.rdb +0 -0
  175. data/test/multiverse/suites/resque/instrumentation_test.rb +73 -0
  176. data/test/multiverse/suites/rum_auto_instrumentation/Envfile +4 -0
  177. data/test/multiverse/suites/rum_auto_instrumentation/config/newrelic.yml +24 -0
  178. data/test/multiverse/suites/rum_auto_instrumentation/responses/worst_case_small.html +5000 -0
  179. data/test/multiverse/suites/rum_auto_instrumentation/sanity_test.rb +102 -0
  180. data/test/multiverse/suites/sinatra/Envfile +13 -0
  181. data/test/multiverse/suites/sinatra/config/newrelic.yml +24 -0
  182. data/test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb +77 -0
  183. data/test/multiverse/suites/sinatra/sinatra_routes_test.rb +46 -0
  184. data/test/multiverse/suites/sinatra/sinatra_test.rb +55 -0
  185. data/test/multiverse/test/multiverse_test.rb +55 -0
  186. data/test/multiverse/test/suite_examples/one/a/Envfile +3 -0
  187. data/test/multiverse/test/suite_examples/one/a/a_test.rb +11 -0
  188. data/test/multiverse/test/suite_examples/one/a/config/newrelic.yml +24 -0
  189. data/test/multiverse/test/suite_examples/one/b/Envfile +3 -0
  190. data/test/multiverse/test/suite_examples/one/b/b_test.rb +11 -0
  191. data/test/multiverse/test/suite_examples/one/b/config/newrelic.yml +24 -0
  192. data/test/multiverse/test/suite_examples/three/a/Envfile +2 -0
  193. data/test/multiverse/test/suite_examples/three/a/fail_test.rb +6 -0
  194. data/test/multiverse/test/suite_examples/three/b/Envfile +2 -0
  195. data/test/multiverse/test/suite_examples/three/b/win_test.rb +6 -0
  196. data/test/multiverse/test/suite_examples/two/a/Envfile +1 -0
  197. data/test/multiverse/test/suite_examples/two/a/fail_test.rb +6 -0
  198. data/test/new_relic/agent/agent/connect_test.rb +151 -227
  199. data/test/new_relic/agent/agent/start_test.rb +68 -118
  200. data/test/new_relic/agent/agent/start_worker_thread_test.rb +12 -74
  201. data/test/new_relic/agent/agent_logger_test.rb +153 -0
  202. data/test/new_relic/agent/agent_test.rb +116 -30
  203. data/test/new_relic/agent/agent_test_controller.rb +1 -1
  204. data/test/new_relic/agent/agent_test_controller_test.rb +42 -10
  205. data/test/new_relic/agent/audit_logger_test.rb +105 -0
  206. data/test/new_relic/agent/beacon_configuration_test.rb +63 -67
  207. data/test/new_relic/agent/browser_monitoring_test.rb +151 -79
  208. data/test/new_relic/agent/busy_calculator_test.rb +7 -0
  209. data/test/new_relic/agent/configuration/environment_source_test.rb +79 -0
  210. data/test/new_relic/agent/configuration/manager_test.rb +204 -0
  211. data/test/new_relic/agent/configuration/server_source_test.rb +45 -0
  212. data/test/new_relic/agent/configuration/yaml_source_test.rb +75 -0
  213. data/test/new_relic/agent/cross_process_monitoring_test.rb +77 -0
  214. data/test/new_relic/agent/database_test.rb +12 -11
  215. data/test/new_relic/agent/error_collector/notice_error_test.rb +64 -53
  216. data/test/new_relic/agent/error_collector_test.rb +33 -19
  217. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +60 -30
  218. data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +39 -0
  219. data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +1 -1
  220. data/test/new_relic/agent/instrumentation/metric_frame_test.rb +6 -0
  221. data/test/new_relic/agent/instrumentation/queue_time_test.rb +14 -0
  222. data/test/new_relic/agent/instrumentation/sinatra_test.rb +25 -0
  223. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +2 -2
  224. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +4 -10
  225. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +3 -15
  226. data/test/new_relic/agent/method_tracer_test.rb +7 -6
  227. data/test/new_relic/agent/mock_scope_listener.rb +3 -0
  228. data/test/new_relic/agent/new_relic_service_test.rb +376 -0
  229. data/test/new_relic/agent/pipe_channel_manager_test.rb +131 -0
  230. data/test/new_relic/agent/pipe_service_test.rb +113 -0
  231. data/test/new_relic/agent/rpm_agent_test.rb +27 -50
  232. data/test/new_relic/agent/sql_sampler_test.rb +81 -56
  233. data/test/new_relic/agent/stats_engine/metric_stats/harvest_test.rb +3 -20
  234. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +12 -1
  235. data/test/new_relic/agent/stats_engine_test.rb +17 -8
  236. data/test/new_relic/agent/thread_profiler_test.rb +537 -0
  237. data/test/new_relic/agent/thread_test.rb +89 -0
  238. data/test/new_relic/agent/threaded_test.rb +65 -0
  239. data/test/new_relic/agent/transaction_info_test.rb +45 -4
  240. data/test/new_relic/agent/transaction_sample_builder_test.rb +8 -7
  241. data/test/new_relic/agent/transaction_sampler_test.rb +193 -204
  242. data/test/new_relic/agent/worker_loop_test.rb +26 -11
  243. data/test/new_relic/agent_test.rb +113 -33
  244. data/test/new_relic/collection_helper_test.rb +7 -8
  245. data/test/new_relic/command/deployments_test.rb +18 -2
  246. data/test/new_relic/control/class_methods_test.rb +0 -18
  247. data/test/new_relic/control/frameworks/rails_test.rb +26 -0
  248. data/test/new_relic/control_test.rb +96 -137
  249. data/test/new_relic/delayed_job_injection_test.rb +6 -1
  250. data/test/new_relic/dispatcher_test.rb +54 -0
  251. data/test/new_relic/fake_collector.rb +283 -0
  252. data/test/new_relic/fake_service.rb +53 -0
  253. data/test/new_relic/fakes_sending_data.rb +30 -0
  254. data/test/new_relic/framework_test.rb +53 -0
  255. data/test/new_relic/load_test.rb +13 -0
  256. data/test/new_relic/local_environment_test.rb +11 -11
  257. data/test/new_relic/metric_data_test.rb +45 -16
  258. data/test/new_relic/noticed_error_test.rb +24 -0
  259. data/test/new_relic/rack/browser_monitoring_test.rb +20 -10
  260. data/test/new_relic/rack/developer_mode_test.rb +13 -7
  261. data/test/new_relic/rack/error_collector_test.rb +74 -0
  262. data/test/new_relic/stats_test.rb +10 -0
  263. data/test/new_relic/transaction_sample/segment_test.rb +23 -4
  264. data/test/new_relic/transaction_sample_test.rb +47 -2
  265. data/test/new_relic/version_number_test.rb +32 -0
  266. data/test/script/build_test_gem.sh +9 -3
  267. data/test/script/ci.sh +108 -35
  268. data/test/script/ci_agent-tests_runner.sh +82 -0
  269. data/test/script/ci_multiverse_runner.sh +63 -0
  270. data/test/test_contexts.rb +1 -0
  271. data/test/test_helper.rb +68 -18
  272. data/ui/helpers/developer_mode_helper.rb +21 -11
  273. data/ui/views/layouts/newrelic_default.rhtml +1 -0
  274. data/ui/views/newrelic/file/images/arrow-close.png +0 -0
  275. data/ui/views/newrelic/file/images/arrow-open.png +0 -0
  276. data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
  277. data/ui/views/newrelic/file/images/file_icon.png +0 -0
  278. data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
  279. data/ui/views/newrelic/show_sample.rhtml +1 -1
  280. data/ui/views/newrelic/threads.rhtml +2 -10
  281. data/vendor/gems/metric_parser-0.1.0.pre1/.specification +116 -0
  282. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_init.rb +7 -0
  283. metadata +191 -65
  284. data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +0 -40
  285. data/lib/new_relic/control/configuration.rb +0 -206
  286. data/lib/new_relic/control/logging_methods.rb +0 -143
  287. data/lib/new_relic/data_serialization.rb +0 -151
  288. data/test/new_relic/control/configuration_test.rb +0 -84
  289. data/test/new_relic/control/logging_methods_test.rb +0 -185
  290. data/test/new_relic/data_serialization_test.rb +0 -208
@@ -20,7 +20,7 @@ module NewRelic
20
20
  def original_spec
21
21
  @original_spec || @metric_spec
22
22
  end
23
-
23
+
24
24
  # assigns a new metric spec, and retains the old metric spec as
25
25
  # @original_spec if it exists currently
26
26
  def metric_spec= new_spec
@@ -36,7 +36,7 @@ module NewRelic
36
36
  def to_json(*a)
37
37
  %Q[{"metric_spec":#{metric_id ? 'null' : metric_spec.to_json},"stats":{"total_exclusive_time":#{stats.total_exclusive_time},"min_call_time":#{stats.min_call_time},"call_count":#{stats.call_count},"sum_of_squares":#{stats.sum_of_squares},"total_call_time":#{stats.total_call_time},"max_call_time":#{stats.max_call_time}},"metric_id":#{metric_id ? metric_id : 'null'}}]
38
38
  end
39
-
39
+
40
40
  def to_s
41
41
  if metric_spec
42
42
  "#{metric_spec.name}(#{metric_spec.scope}): #{stats}"
@@ -44,8 +44,16 @@ module NewRelic
44
44
  "#{metric_id}: #{stats}"
45
45
  end
46
46
  end
47
+
47
48
  def inspect
48
49
  "#<MetricData metric_spec:#{metric_spec.inspect}, stats:#{stats.inspect}, metric_id:#{metric_id.inspect}>"
49
50
  end
51
+
52
+ def to_collector_array(encoder=nil)
53
+ stat_key = metric_id || { 'name' => metric_spec.name, 'scope' => metric_spec.scope }
54
+ [ stat_key,
55
+ [ stats.call_count, stats.total_call_time, stats.total_exclusive_time,
56
+ stats.min_call_time, stats.max_call_time, stats.sum_of_squares ] ]
57
+ end
50
58
  end
51
59
  end
@@ -10,9 +10,13 @@ class NewRelic::MetricSpec
10
10
  # Need a "zero-arg" constructor so it can be instantiated from java (using
11
11
  # jruby) for sending responses to ruby agents from the java collector.
12
12
  #
13
- def initialize(metric_name = '', metric_scope = '')
13
+ def initialize(metric_name = '', metric_scope = nil)
14
14
  self.name = (metric_name || '') && metric_name[LENGTH_RANGE]
15
- self.scope = metric_scope && metric_scope[LENGTH_RANGE]
15
+ if metric_scope
16
+ self.scope = metric_scope && metric_scope[LENGTH_RANGE]
17
+ else
18
+ self.scope = ''
19
+ end
16
20
  end
17
21
 
18
22
  # truncates the name and scope to the MAX_LENGTH
@@ -40,7 +44,7 @@ class NewRelic::MetricSpec
40
44
  # return a new metric spec if the given regex
41
45
  # matches the name or scope.
42
46
  def sub(pattern, replacement, apply_to_scope = true)
43
- NewRelic::Control.instance.log.warn("The sub method on metric specs is deprecated") rescue nil
47
+ ::NewRelic::Agent.logger.warn("The sub method on metric specs is deprecated") rescue nil
44
48
  return nil if name !~ pattern &&
45
49
  (!apply_to_scope || scope.nil? || scope !~ pattern)
46
50
  new_name = name.sub(pattern, replacement)[LENGTH_RANGE]
@@ -2,28 +2,51 @@
2
2
  class NewRelic::NoticedError
3
3
  extend NewRelic::CollectionHelper
4
4
  attr_accessor :path, :timestamp, :params, :exception_class, :message
5
+ attr_reader :exception_id
5
6
 
6
7
  def initialize(path, data, exception, timestamp = Time.now)
7
- self.path = path
8
- self.params = NewRelic::NoticedError.normalize_params(data)
8
+ @exception_id = exception.object_id
9
+ @path = path
10
+ @params = NewRelic::NoticedError.normalize_params(data)
9
11
 
10
- self.exception_class = exception.is_a?(Exception) ? exception.class.name : 'Error'
12
+ @exception_class = exception.is_a?(Exception) ? exception.class.name : 'Error'
11
13
 
12
14
  if exception.respond_to?('original_exception')
13
- self.message = exception.original_exception.message.to_s
15
+ @message = exception.original_exception.message.to_s
14
16
  else
15
- self.message = (exception || '<no message>').to_s
17
+ @message = (exception || '<no message>').to_s
18
+ end
19
+
20
+ unless @message.is_a?(String)
21
+ # In pre-1.9.3, Exception.new({}).to_s.class != String
22
+ # That is, Exception#to_s may not return a String instance if one wasn't
23
+ # passed in upon creation of the Exception. So, try to generate a useful
24
+ # String representation of the exception message, falling back to failsafe
25
+ @message = String(@message.inspect) rescue '<unknown message type>'
16
26
  end
17
27
 
18
28
  # clamp long messages to 4k so that we don't send a lot of
19
29
  # overhead across the wire
20
- self.message = self.message[0..4095] if self.message.length > 4096
30
+ @message = @message[0..4095] if @message.length > 4096
21
31
 
22
32
  # obfuscate error message if necessary
23
- if NewRelic::Control.instance.fetch('high_security', false)
24
- self.message = NewRelic::Agent::Database.obfuscate_sql(self.message)
33
+ if NewRelic::Agent.config[:high_security]
34
+ @message = NewRelic::Agent::Database.obfuscate_sql(@message)
25
35
  end
26
36
 
27
- self.timestamp = timestamp
37
+ @timestamp = timestamp
38
+ end
39
+
40
+ def ==(other)
41
+ if other.respond_to?(:exception_id)
42
+ @exception_id == other.exception_id
43
+ else
44
+ false
45
+ end
46
+ end
47
+
48
+ def to_collector_array(encoder=nil)
49
+ [ (@timestamp.to_f * 1000).round, @path, @message, @exception_class,
50
+ @params ]
28
51
  end
29
52
  end
@@ -0,0 +1,4 @@
1
+ module NewRelic
2
+ module Rack
3
+ end
4
+ end
@@ -9,17 +9,6 @@ module NewRelic::Rack
9
9
 
10
10
  # method required by Rack interface
11
11
  def call(env)
12
- # Two experimental options for allowing TT capture based on http params
13
- #
14
- # if req.params['nr_capture_deep_tt']
15
- # NewRelic::Agent::TransactionInfo.get.force_persist = true
16
- # NewRelic::Agent::TransactionInfo.get.capture_deep_tt = true
17
- # end
18
-
19
- # if req.params['nr_capture_tt']
20
- # NewRelic::Agent::TransactionInfo.get.force_persist = true
21
- # end
22
-
23
12
  result = @app.call(env) # [status, headers, response]
24
13
 
25
14
  if (NewRelic::Agent.browser_timing_header != "") && should_instrument?(result[0], result[1])
@@ -46,29 +35,49 @@ module NewRelic::Rack
46
35
  response.each {|fragment| source ? (source << fragment.to_s) : (source = fragment.to_s)}
47
36
  return nil unless source
48
37
 
49
- body_start = source.index("<body")
50
- body_close = source.rindex("</body>")
51
38
 
52
- if body_start && body_close
39
+ # Only scan the first 50k (roughly) then give up.
40
+ beginning_of_source = source[0..50_000]
41
+ # Don't scan for body close unless we find body start
42
+ if (body_start = beginning_of_source.index("<body")) && (body_close = source.rindex("</body>"))
43
+
53
44
  footer = NewRelic::Agent.browser_timing_footer
54
45
  header = NewRelic::Agent.browser_timing_header
55
46
 
56
- if source.include?('X-UA-Compatible')
57
- # put at end of header if UA-Compatible meta tag found
58
- head_pos = source.index("</head>")
59
- elsif head_open = source.index("<head")
47
+ x_ua_compatible_found = beginning_of_source.include?('X-UA-Compatible')
48
+
49
+ head_pos = if x_ua_compatible_found
50
+ # put at end of header if X-UA-Compatible meta tag found
51
+ ::NewRelic::Agent.logger.debug "Detected X-UA-Compatible meta tag. Attempting to insert RUM header at end of head."
52
+ beginning_of_source.index("</head>")
53
+ elsif head_open = beginning_of_source.index("<head")
54
+ ::NewRelic::Agent.logger.debug "Attempting to insert RUM header at beginning of head."
60
55
  # put at the beginning of the header
61
- head_pos = source.index(">", head_open) + 1
56
+ beginning_of_source.index(">", head_open) + 1
62
57
  else
63
- # put the header right above body start
64
- head_pos = body_start
58
+ ::NewRelic::Agent.logger.debug "Failed to detect head tag. Attempting to insert RUM header at above body tag."
59
+ # otherwise put the header right above body start
60
+ body_start
65
61
  end
66
62
 
67
- source = source[0..(head_pos-1)] + header + source[head_pos..(body_close-1)] + footer + source[body_close..-1]
68
-
69
- headers['Content-Length'] = source.length.to_s if headers['Content-Length']
63
+ # check that head_pos is less than body close. If it's not something
64
+ # is really weird and we should punt.
65
+ if head_pos && (head_pos < body_close)
66
+ # rebuild the source
67
+ source = source[0..(head_pos-1)] <<
68
+ header <<
69
+ source[head_pos..(body_close-1)] <<
70
+ footer <<
71
+ source[body_close..-1]
72
+ else
73
+ if head_pos
74
+ ::NewRelic::Agent.logger.debug "Skipping RUM instrumentation. Failed to detect head tags."
75
+ else
76
+ ::NewRelic::Agent.logger.debug "Skipping RUM instrumentation. Detected head is after detected body close."
77
+ end
78
+ end
70
79
  end
71
-
80
+ headers['Content-Length'] = source.length.to_s if headers['Content-Length']
72
81
  source
73
82
  end
74
83
  end
@@ -229,6 +229,9 @@ module NewRelic
229
229
  if params['d']
230
230
  @sql_segments.sort!{|a,b| b.duration <=> a.duration }
231
231
  end
232
+
233
+ sort_method = params['sort'] || :total_time
234
+ @profile_options = {:min_percent => 0.5, :sort_method => sort_method.to_sym}
232
235
 
233
236
  render(:show_sample)
234
237
  end
@@ -0,0 +1,56 @@
1
+ module NewRelic::Rack
2
+ class ErrorCollector
3
+ def initialize(app, options={})
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ @app.call(env)
9
+ rescue Exception => exception
10
+ request = Rack::Request.new(env)
11
+ if !should_ignore_error?(exception, request)
12
+ NewRelic::Agent.instance.error_collector.notice_error(exception,
13
+ :uri => request.path,
14
+ :referer => request.referer,
15
+ :request_params => request.params)
16
+ end
17
+ raise exception
18
+ end
19
+
20
+ def should_ignore_error?(error, request)
21
+ NewRelic::Agent.instance.error_collector.error_is_ignored?(error) ||
22
+ ignored_in_controller?(error, request)
23
+ end
24
+
25
+ def ignored_in_controller?(exception, request)
26
+ if request.env['action_dispatch.request.parameters']
27
+ ignore_actions = newrelic_ignore_for_controller(request.env['action_dispatch.request.parameters']['controller'])
28
+ action_name = request.env['action_dispatch.request.parameters']['action']
29
+
30
+ case ignore_actions
31
+ when nil; false
32
+ when Hash
33
+ only_actions = Array(ignore_actions[:only])
34
+ except_actions = Array(ignore_actions[:except])
35
+ only_actions.include?(action_name.to_sym) ||
36
+ (except_actions.any? &&
37
+ !except_actions.include?(action_name.to_sym))
38
+ else
39
+ true
40
+ end
41
+ end
42
+ end
43
+
44
+ def newrelic_ignore_for_controller(controller_name)
45
+ if controller_name
46
+ controller_constant_name = (controller_name + "_controller").camelize
47
+ if Object.const_defined?(controller_constant_name)
48
+ controller = controller_constant_name.constantize
49
+ controller.instance_variable_get(:@do_not_trace)
50
+ end
51
+ end
52
+ rescue NameError
53
+ nil
54
+ end
55
+ end
56
+ end
@@ -219,13 +219,15 @@ module NewRelic
219
219
  super
220
220
  end
221
221
 
222
- def to_json(*a)
223
- {'call_count' => call_count,
224
- 'min_call_time' => min_call_time,
225
- 'max_call_time' => max_call_time,
226
- 'total_call_time' => total_call_time,
227
- 'total_exclusive_time' => total_exclusive_time,
228
- 'sum_of_squares' => sum_of_squares}.to_json(*a)
222
+ def to_json(*_)
223
+ {
224
+ 'call_count' => call_count.to_i,
225
+ 'min_call_time' => min_call_time.to_f,
226
+ 'max_call_time' => max_call_time.to_f,
227
+ 'total_call_time' => total_call_time.to_f,
228
+ 'total_exclusive_time' => total_exclusive_time.to_f,
229
+ 'sum_of_squares' => sum_of_squares.to_f
230
+ }.to_json(*_)
229
231
  end
230
232
 
231
233
 
@@ -1,3 +1,5 @@
1
+ require 'base64'
2
+
1
3
  require 'new_relic/transaction_sample/segment'
2
4
  require 'new_relic/transaction_sample/summary_segment'
3
5
  require 'new_relic/transaction_sample/fake_segment'
@@ -51,15 +53,20 @@ module NewRelic
51
53
  @start_time - @@start_time.to_f
52
54
  end
53
55
 
54
- # Used in the server only
55
- def to_json(options = {}) #:nodoc:
56
- map = {:sample_id => @sample_id,
57
- :start_time => @start_time,
58
- :root_segment => @root_segment}
59
- if @params && !@params.empty?
60
- map[:params] = @params
61
- end
62
- map.to_json
56
+ def to_json
57
+ JSON.dump(self.to_array)
58
+ end
59
+
60
+ def to_array
61
+ [ @start_time.to_f, @params[:request_params], @params[:custom_params],
62
+ @root_segment.to_array ]
63
+ end
64
+
65
+ def to_collector_array(encoder)
66
+ trace_tree = encoder.encode(self.to_array)
67
+ [ Helper.time_to_millis(@start_time), Helper.time_to_millis(duration),
68
+ @params[:path], @params[:uri], trace_tree, @guid, nil,
69
+ !!@force_persist ]
63
70
  end
64
71
 
65
72
  def start_time
@@ -134,10 +141,10 @@ module NewRelic
134
141
  regex = Regexp.new(regex)
135
142
 
136
143
  sample = TransactionSample.new(@start_time, sample_id)
137
-
144
+
138
145
  sample.params = params.dup
139
146
  sample.params[:segment_count] = 0
140
-
147
+
141
148
  delta = build_segment_with_omissions(sample, 0.0, @root_segment, sample.root_segment, regex)
142
149
  sample.root_segment.end_trace(@root_segment.exit_timestamp - delta)
143
150
  sample.profile = self.profile
@@ -159,11 +166,7 @@ module NewRelic
159
166
  sample.guid = self.guid
160
167
  sample.force_persist = self.force_persist if self.force_persist
161
168
 
162
- begin
163
- build_segment_for_transfer(sample, @root_segment, sample.root_segment, options)
164
- ensure
165
- NewRelic::Agent::Database.close_connections
166
- end
169
+ build_segment_for_transfer(sample, @root_segment, sample.root_segment, options)
167
170
 
168
171
  sample.root_segment.end_trace(@root_segment.exit_timestamp)
169
172
  sample
@@ -175,8 +178,6 @@ module NewRelic
175
178
 
176
179
  private
177
180
 
178
-
179
-
180
181
  HEX_DIGITS = (0..15).map{|i| i.to_s(16)}
181
182
  # generate a random 64 bit uuid
182
183
  def generate_guid
@@ -1,4 +1,5 @@
1
1
  require 'new_relic/transaction_sample'
2
+
2
3
  module NewRelic
3
4
  class TransactionSample
4
5
  class Segment
@@ -15,13 +16,13 @@ module NewRelic
15
16
  @metric_name = metric_name || '<unknown>'
16
17
  @segment_id = segment_id || object_id
17
18
  end
18
-
19
+
19
20
  # sets the final timestamp on a segment to indicate the exit
20
21
  # point of the segment
21
22
  def end_trace(timestamp)
22
23
  @exit_timestamp = timestamp
23
24
  end
24
-
25
+
25
26
  def add_called_segment(s)
26
27
  @called_segments ||= []
27
28
  @called_segments << s
@@ -32,18 +33,15 @@ module NewRelic
32
33
  to_debug_str(0)
33
34
  end
34
35
 
35
- def to_json(options={})
36
- hash = {
37
- :entry_timestamp => @entry_timestamp,
38
- :exit_timestamp => @exit_timestamp,
39
- :metric_name => @metric_name,
40
- :segment_id => @segment_id,
41
- }
42
-
43
- hash[:called_segments] = called_segments if !called_segments.empty?
44
- hash[:params] = @params if @params && !@params.empty?
36
+ def to_array
37
+ [ (@entry_timestamp.to_f * 1000).round,
38
+ (@exit_timestamp.to_f * 1000).round,
39
+ @metric_name, (@params || {}) ] +
40
+ [ (@called_segments ? @called_segments.map{|s| s.to_array} : []) ]
41
+ end
45
42
 
46
- hash.to_json
43
+ def to_json
44
+ JSON.dump(self.to_array)
47
45
  end
48
46
 
49
47
  def path_string
@@ -97,13 +95,13 @@ module NewRelic
97
95
  end
98
96
  d
99
97
  end
100
-
98
+
101
99
  def count_segments
102
100
  count = 1
103
101
  called_segments.each { | seg | count += seg.count_segments }
104
102
  count
105
103
  end
106
-
104
+
107
105
  # Walk through the tree and truncate the segments in a
108
106
  # depth-first manner
109
107
  def truncate(max)
@@ -1,10 +1,26 @@
1
1
  #!/usr/bin/ruby
2
+
2
3
  module NewRelic
3
4
  module VERSION #:nodoc:
5
+ def self.parse_build_from_gemspec(path)
6
+ if File.exist?(path)
7
+ version_string = if Kernel.const_defined?(:Gem)
8
+ spec = Gem::Specification.load(path)
9
+ spec.version.to_s if spec
10
+ else
11
+ md = File.read(path).match(/s\.version\s*=\s*"(.*)"/)
12
+ md[1] if md
13
+ end
14
+ version_string && version_string.split('.', 4)[3]
15
+ end
16
+ end
17
+
18
+ GEMSPEC_PATH = File.join(File.dirname(__FILE__), '..', '..', 'newrelic_rpm.gemspec')
4
19
  MAJOR = 3
5
- MINOR = 3
6
- TINY = 4
7
- BUILD = 1 # Set to nil for a release, 'beta1', 'alpha', etc for prerelease builds
20
+ MINOR = 5
21
+ TINY = 5
22
+ BUILD = parse_build_from_gemspec(GEMSPEC_PATH)
23
+
8
24
  STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
9
25
  end
10
26