wd_newrelic_rpm 3.3.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (264) hide show
  1. data/CHANGELOG +591 -0
  2. data/LICENSE +64 -0
  3. data/README.rdoc +179 -0
  4. data/bin/mongrel_rpm +33 -0
  5. data/bin/newrelic +13 -0
  6. data/bin/newrelic_cmd +5 -0
  7. data/cert/cacert.pem +118 -0
  8. data/cert/oldsite.pem +28 -0
  9. data/cert/site.pem +27 -0
  10. data/install.rb +9 -0
  11. data/lib/conditional_vendored_dependency_detection.rb +3 -0
  12. data/lib/conditional_vendored_metric_parser.rb +5 -0
  13. data/lib/new_relic/agent.rb +467 -0
  14. data/lib/new_relic/agent/agent.rb +1325 -0
  15. data/lib/new_relic/agent/beacon_configuration.rb +121 -0
  16. data/lib/new_relic/agent/browser_monitoring.rb +142 -0
  17. data/lib/new_relic/agent/busy_calculator.rb +99 -0
  18. data/lib/new_relic/agent/chained_call.rb +13 -0
  19. data/lib/new_relic/agent/database.rb +223 -0
  20. data/lib/new_relic/agent/error_collector.rb +251 -0
  21. data/lib/new_relic/agent/instrumentation.rb +9 -0
  22. data/lib/new_relic/agent/instrumentation/active_merchant.rb +29 -0
  23. data/lib/new_relic/agent/instrumentation/active_record.rb +137 -0
  24. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +68 -0
  25. data/lib/new_relic/agent/instrumentation/authlogic.rb +19 -0
  26. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +443 -0
  27. data/lib/new_relic/agent/instrumentation/data_mapper.rb +238 -0
  28. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +52 -0
  29. data/lib/new_relic/agent/instrumentation/memcache.rb +80 -0
  30. data/lib/new_relic/agent/instrumentation/merb/controller.rb +41 -0
  31. data/lib/new_relic/agent/instrumentation/merb/errors.rb +29 -0
  32. data/lib/new_relic/agent/instrumentation/metric_frame.rb +353 -0
  33. data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +80 -0
  34. data/lib/new_relic/agent/instrumentation/net.rb +29 -0
  35. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +37 -0
  36. data/lib/new_relic/agent/instrumentation/queue_time.rb +210 -0
  37. data/lib/new_relic/agent/instrumentation/rack.rb +98 -0
  38. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +114 -0
  39. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +42 -0
  40. data/lib/new_relic/agent/instrumentation/rails/errors.rb +42 -0
  41. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +180 -0
  42. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +37 -0
  43. data/lib/new_relic/agent/instrumentation/sinatra.rb +78 -0
  44. data/lib/new_relic/agent/instrumentation/sunspot.rb +29 -0
  45. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +21 -0
  46. data/lib/new_relic/agent/method_tracer.rb +528 -0
  47. data/lib/new_relic/agent/sampler.rb +50 -0
  48. data/lib/new_relic/agent/samplers/cpu_sampler.rb +58 -0
  49. data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +40 -0
  50. data/lib/new_relic/agent/samplers/memory_sampler.rb +143 -0
  51. data/lib/new_relic/agent/samplers/object_sampler.rb +26 -0
  52. data/lib/new_relic/agent/shim_agent.rb +29 -0
  53. data/lib/new_relic/agent/sql_sampler.rb +286 -0
  54. data/lib/new_relic/agent/stats_engine.rb +26 -0
  55. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +123 -0
  56. data/lib/new_relic/agent/stats_engine/metric_stats.rb +187 -0
  57. data/lib/new_relic/agent/stats_engine/samplers.rb +95 -0
  58. data/lib/new_relic/agent/stats_engine/transactions.rb +125 -0
  59. data/lib/new_relic/agent/transaction_info.rb +74 -0
  60. data/lib/new_relic/agent/transaction_sample_builder.rb +116 -0
  61. data/lib/new_relic/agent/transaction_sampler.rb +468 -0
  62. data/lib/new_relic/agent/worker_loop.rb +89 -0
  63. data/lib/new_relic/collection_helper.rb +77 -0
  64. data/lib/new_relic/command.rb +85 -0
  65. data/lib/new_relic/commands/deployments.rb +105 -0
  66. data/lib/new_relic/commands/install.rb +80 -0
  67. data/lib/new_relic/control.rb +46 -0
  68. data/lib/new_relic/control/class_methods.rb +53 -0
  69. data/lib/new_relic/control/configuration.rb +206 -0
  70. data/lib/new_relic/control/frameworks.rb +10 -0
  71. data/lib/new_relic/control/frameworks/external.rb +16 -0
  72. data/lib/new_relic/control/frameworks/merb.rb +31 -0
  73. data/lib/new_relic/control/frameworks/rails.rb +164 -0
  74. data/lib/new_relic/control/frameworks/rails3.rb +75 -0
  75. data/lib/new_relic/control/frameworks/ruby.rb +42 -0
  76. data/lib/new_relic/control/frameworks/sinatra.rb +20 -0
  77. data/lib/new_relic/control/instance_methods.rb +179 -0
  78. data/lib/new_relic/control/instrumentation.rb +100 -0
  79. data/lib/new_relic/control/logging_methods.rb +143 -0
  80. data/lib/new_relic/control/profiling.rb +25 -0
  81. data/lib/new_relic/control/server_methods.rb +114 -0
  82. data/lib/new_relic/data_serialization.rb +151 -0
  83. data/lib/new_relic/delayed_job_injection.rb +51 -0
  84. data/lib/new_relic/language_support.rb +73 -0
  85. data/lib/new_relic/local_environment.rb +428 -0
  86. data/lib/new_relic/merbtasks.rb +6 -0
  87. data/lib/new_relic/metric_data.rb +51 -0
  88. data/lib/new_relic/metric_spec.rb +76 -0
  89. data/lib/new_relic/metrics.rb +9 -0
  90. data/lib/new_relic/noticed_error.rb +29 -0
  91. data/lib/new_relic/rack/browser_monitoring.rb +76 -0
  92. data/lib/new_relic/rack/developer_mode.rb +268 -0
  93. data/lib/new_relic/recipes.rb +77 -0
  94. data/lib/new_relic/stats.rb +335 -0
  95. data/lib/new_relic/timer_lib.rb +27 -0
  96. data/lib/new_relic/transaction_analysis.rb +77 -0
  97. data/lib/new_relic/transaction_analysis/segment_summary.rb +49 -0
  98. data/lib/new_relic/transaction_sample.rb +261 -0
  99. data/lib/new_relic/transaction_sample/composite_segment.rb +27 -0
  100. data/lib/new_relic/transaction_sample/fake_segment.rb +9 -0
  101. data/lib/new_relic/transaction_sample/segment.rb +203 -0
  102. data/lib/new_relic/transaction_sample/summary_segment.rb +21 -0
  103. data/lib/new_relic/url_rule.rb +14 -0
  104. data/lib/new_relic/version.rb +55 -0
  105. data/lib/newrelic_rpm.rb +49 -0
  106. data/lib/tasks/all.rb +4 -0
  107. data/lib/tasks/install.rake +7 -0
  108. data/lib/tasks/tests.rake +19 -0
  109. data/newrelic.yml +265 -0
  110. data/newrelic_rpm.gemspec +312 -0
  111. data/recipes/newrelic.rb +6 -0
  112. data/test/active_record_fixtures.rb +77 -0
  113. data/test/config/newrelic.yml +48 -0
  114. data/test/config/test_control.rb +48 -0
  115. data/test/fixtures/proc_cpuinfo.txt +575 -0
  116. data/test/new_relic/agent/agent/connect_test.rb +403 -0
  117. data/test/new_relic/agent/agent/start_test.rb +255 -0
  118. data/test/new_relic/agent/agent/start_worker_thread_test.rb +153 -0
  119. data/test/new_relic/agent/agent_test.rb +140 -0
  120. data/test/new_relic/agent/agent_test_controller.rb +77 -0
  121. data/test/new_relic/agent/agent_test_controller_test.rb +382 -0
  122. data/test/new_relic/agent/apdex_from_server_test.rb +9 -0
  123. data/test/new_relic/agent/beacon_configuration_test.rb +111 -0
  124. data/test/new_relic/agent/browser_monitoring_test.rb +323 -0
  125. data/test/new_relic/agent/busy_calculator_test.rb +81 -0
  126. data/test/new_relic/agent/database_test.rb +149 -0
  127. data/test/new_relic/agent/error_collector/notice_error_test.rb +257 -0
  128. data/test/new_relic/agent/error_collector_test.rb +192 -0
  129. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +576 -0
  130. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +34 -0
  131. data/test/new_relic/agent/instrumentation/instrumentation_test.rb +11 -0
  132. data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +171 -0
  133. data/test/new_relic/agent/instrumentation/metric_frame_test.rb +50 -0
  134. data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +84 -0
  135. data/test/new_relic/agent/instrumentation/queue_time_test.rb +382 -0
  136. data/test/new_relic/agent/instrumentation/rack_test.rb +35 -0
  137. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +184 -0
  138. data/test/new_relic/agent/memcache_instrumentation_test.rb +143 -0
  139. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +164 -0
  140. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +234 -0
  141. data/test/new_relic/agent/method_tracer_test.rb +386 -0
  142. data/test/new_relic/agent/mock_scope_listener.rb +23 -0
  143. data/test/new_relic/agent/rpm_agent_test.rb +149 -0
  144. data/test/new_relic/agent/sampler_test.rb +19 -0
  145. data/test/new_relic/agent/shim_agent_test.rb +20 -0
  146. data/test/new_relic/agent/sql_sampler_test.rb +192 -0
  147. data/test/new_relic/agent/stats_engine/metric_stats/harvest_test.rb +150 -0
  148. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +82 -0
  149. data/test/new_relic/agent/stats_engine/samplers_test.rb +99 -0
  150. data/test/new_relic/agent/stats_engine_test.rb +220 -0
  151. data/test/new_relic/agent/transaction_info_test.rb +13 -0
  152. data/test/new_relic/agent/transaction_sample_builder_test.rb +219 -0
  153. data/test/new_relic/agent/transaction_sampler_test.rb +967 -0
  154. data/test/new_relic/agent/worker_loop_test.rb +66 -0
  155. data/test/new_relic/agent_test.rb +187 -0
  156. data/test/new_relic/collection_helper_test.rb +149 -0
  157. data/test/new_relic/command/deployments_test.rb +68 -0
  158. data/test/new_relic/control/class_methods_test.rb +62 -0
  159. data/test/new_relic/control/configuration_test.rb +84 -0
  160. data/test/new_relic/control/logging_methods_test.rb +185 -0
  161. data/test/new_relic/control_test.rb +256 -0
  162. data/test/new_relic/data_serialization_test.rb +208 -0
  163. data/test/new_relic/delayed_job_injection_test.rb +16 -0
  164. data/test/new_relic/local_environment_test.rb +85 -0
  165. data/test/new_relic/metric_data_test.rb +125 -0
  166. data/test/new_relic/metric_parser/metric_parser_test.rb +11 -0
  167. data/test/new_relic/metric_spec_test.rb +95 -0
  168. data/test/new_relic/rack/all_test.rb +11 -0
  169. data/test/new_relic/rack/browser_monitoring_test.rb +142 -0
  170. data/test/new_relic/rack/developer_mode_helper_test.rb +141 -0
  171. data/test/new_relic/rack/developer_mode_test.rb +74 -0
  172. data/test/new_relic/stats_test.rb +411 -0
  173. data/test/new_relic/transaction_analysis/segment_summary_test.rb +91 -0
  174. data/test/new_relic/transaction_analysis_test.rb +121 -0
  175. data/test/new_relic/transaction_sample/composite_segment_test.rb +35 -0
  176. data/test/new_relic/transaction_sample/fake_segment_test.rb +17 -0
  177. data/test/new_relic/transaction_sample/segment_test.rb +389 -0
  178. data/test/new_relic/transaction_sample/summary_segment_test.rb +31 -0
  179. data/test/new_relic/transaction_sample_subtest_test.rb +56 -0
  180. data/test/new_relic/transaction_sample_test.rb +177 -0
  181. data/test/new_relic/version_number_test.rb +89 -0
  182. data/test/script/build_test_gem.sh +51 -0
  183. data/test/script/ci.sh +94 -0
  184. data/test/script/ci_bench.sh +52 -0
  185. data/test/test_contexts.rb +29 -0
  186. data/test/test_helper.rb +155 -0
  187. data/ui/helpers/developer_mode_helper.rb +357 -0
  188. data/ui/helpers/google_pie_chart.rb +48 -0
  189. data/ui/views/layouts/newrelic_default.rhtml +47 -0
  190. data/ui/views/newrelic/_explain_plans.rhtml +27 -0
  191. data/ui/views/newrelic/_sample.rhtml +20 -0
  192. data/ui/views/newrelic/_segment.rhtml +28 -0
  193. data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
  194. data/ui/views/newrelic/_segment_row.rhtml +12 -0
  195. data/ui/views/newrelic/_show_sample_detail.rhtml +24 -0
  196. data/ui/views/newrelic/_show_sample_sql.rhtml +24 -0
  197. data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
  198. data/ui/views/newrelic/_sql_row.rhtml +16 -0
  199. data/ui/views/newrelic/_stack_trace.rhtml +15 -0
  200. data/ui/views/newrelic/_table.rhtml +12 -0
  201. data/ui/views/newrelic/explain_sql.rhtml +43 -0
  202. data/ui/views/newrelic/file/images/arrow-close.png +0 -0
  203. data/ui/views/newrelic/file/images/arrow-open.png +0 -0
  204. data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
  205. data/ui/views/newrelic/file/images/file_icon.png +0 -0
  206. data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
  207. data/ui/views/newrelic/file/images/new-relic-rpm-desktop.gif +0 -0
  208. data/ui/views/newrelic/file/images/new_relic_rpm_desktop.gif +0 -0
  209. data/ui/views/newrelic/file/images/textmate.png +0 -0
  210. data/ui/views/newrelic/file/javascript/jquery-1.4.2.js +6240 -0
  211. data/ui/views/newrelic/file/javascript/transaction_sample.js +120 -0
  212. data/ui/views/newrelic/file/stylesheets/style.css +490 -0
  213. data/ui/views/newrelic/index.rhtml +71 -0
  214. data/ui/views/newrelic/sample_not_found.rhtml +2 -0
  215. data/ui/views/newrelic/show_sample.rhtml +80 -0
  216. data/ui/views/newrelic/show_source.rhtml +3 -0
  217. data/ui/views/newrelic/threads.rhtml +53 -0
  218. data/vendor/gems/dependency_detection-0.0.1.build/LICENSE +5 -0
  219. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +67 -0
  220. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection/version.rb +3 -0
  221. data/vendor/gems/metric_parser-0.1.0.pre1/lib/metric_parser.rb +1 -0
  222. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser.rb +64 -0
  223. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/action_mailer.rb +14 -0
  224. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_merchant.rb +31 -0
  225. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_record.rb +33 -0
  226. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/apdex.rb +89 -0
  227. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/background_transaction.rb +7 -0
  228. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/client.rb +46 -0
  229. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller.rb +67 -0
  230. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_cpu.rb +43 -0
  231. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_ext.rb +17 -0
  232. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database.rb +48 -0
  233. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database_pool.rb +24 -0
  234. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net.rb +28 -0
  235. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net_parser.rb +17 -0
  236. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/errors.rb +11 -0
  237. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/external.rb +55 -0
  238. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/frontend.rb +40 -0
  239. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/gc.rb +20 -0
  240. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/hibernate_session.rb +7 -0
  241. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java.rb +31 -0
  242. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java_parser.rb +17 -0
  243. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp.rb +34 -0
  244. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp_tag.rb +7 -0
  245. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/mem_cache.rb +55 -0
  246. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb +135 -0
  247. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/orm.rb +27 -0
  248. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/other_transaction.rb +40 -0
  249. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet.rb +7 -0
  250. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_context_listener.rb +7 -0
  251. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_filter.rb +7 -0
  252. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr.rb +27 -0
  253. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr_request_handler.rb +15 -0
  254. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring.rb +54 -0
  255. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring_controller.rb +6 -0
  256. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring_view.rb +6 -0
  257. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_action.rb +20 -0
  258. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_result.rb +20 -0
  259. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/version.rb +5 -0
  260. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/view.rb +70 -0
  261. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_frontend.rb +18 -0
  262. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_service.rb +14 -0
  263. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_transaction.rb +133 -0
  264. metadata +376 -0
@@ -0,0 +1,251 @@
1
+ module NewRelic
2
+ module Agent
3
+ # This class collects errors from the parent application, storing
4
+ # them until they are harvested and transmitted to the server
5
+ class ErrorCollector
6
+ include NewRelic::CollectionHelper
7
+
8
+ # Defined the methods that need to be stubbed out when the
9
+ # agent is disabled
10
+ module Shim #:nodoc:
11
+ def notice_error(*args); end
12
+ end
13
+
14
+ # Maximum possible length of the queue - defaults to 20, may be
15
+ # made configurable in the future. This is a tradeoff between
16
+ # memory and data retention
17
+ MAX_ERROR_QUEUE_LENGTH = 20 unless defined? MAX_ERROR_QUEUE_LENGTH
18
+
19
+ attr_accessor :enabled
20
+ attr_reader :config_enabled
21
+
22
+ # Returns a new error collector
23
+ def initialize
24
+ @errors = []
25
+ # lookup of exception class names to ignore. Hash for fast access
26
+ @ignore = {}
27
+
28
+ config = NewRelic::Control.instance.fetch('error_collector', {})
29
+
30
+ @enabled = @config_enabled = config.fetch('enabled', true)
31
+ @capture_source = config.fetch('capture_source', true)
32
+
33
+ ignore_errors = config.fetch('ignore_errors', "")
34
+ ignore_errors = ignore_errors.split(",") if ignore_errors.is_a? String
35
+ ignore_errors.each { |error| error.strip! }
36
+ ignore(ignore_errors)
37
+ @lock = Mutex.new
38
+ end
39
+
40
+ # Helper method to get the NewRelic::Control.instance
41
+ def control
42
+ NewRelic::Control.instance
43
+ end
44
+
45
+ # Returns the error filter proc that is used to check if an
46
+ # error should be reported. When given a block, resets the
47
+ # filter to the provided block. The define_method() is used to
48
+ # wrap the block in a lambda so return statements don't result in a
49
+ # LocalJump exception.
50
+ def ignore_error_filter(&block)
51
+ if block
52
+ self.class.class_eval { define_method(:ignore_filter_proc, &block) }
53
+ @ignore_filter = method(:ignore_filter_proc)
54
+ else
55
+ @ignore_filter
56
+ end
57
+ end
58
+
59
+ # errors is an array of Exception Class Names
60
+ #
61
+ def ignore(errors)
62
+ errors.each { |error| @ignore[error] = true; log.debug("Ignoring errors of type '#{error}'") }
63
+ end
64
+
65
+ # This module was extracted from the notice_error method - it is
66
+ # internally tested and can be refactored without major issues.
67
+ module NoticeError
68
+ # Whether the error collector is disabled or not
69
+ def disabled?
70
+ !@enabled
71
+ end
72
+
73
+ # Checks the provided error against the error filter, if there
74
+ # is an error filter
75
+ def filtered_by_error_filter?(error)
76
+ return unless @ignore_filter
77
+ !@ignore_filter.call(error)
78
+ end
79
+
80
+ # Checks the array of error names and the error filter against
81
+ # the provided error
82
+ def filtered_error?(error)
83
+ @ignore[error.class.name] || filtered_by_error_filter?(error)
84
+ end
85
+
86
+ # an error is ignored if it is nil or if it is filtered
87
+ def error_is_ignored?(error)
88
+ error && filtered_error?(error)
89
+ end
90
+
91
+ # Increments a statistic that tracks total error rate
92
+ def increment_error_count!
93
+ NewRelic::Agent.get_stats("Errors/all").increment_count
94
+ end
95
+
96
+ # whether we should return early from the notice_error process
97
+ # - based on whether the error is ignored or the error
98
+ # collector is disabled
99
+ def should_exit_notice_error?(exception)
100
+ if @enabled
101
+ if !error_is_ignored?(exception)
102
+ increment_error_count!
103
+ return exception.nil? # exit early if the exception is nil
104
+ end
105
+ end
106
+ # disabled or an ignored error, per above
107
+ true
108
+ end
109
+
110
+ # acts just like Hash#fetch, but deletes the key from the hash
111
+ def fetch_from_options(options, key, default=nil)
112
+ options.delete(key) || default
113
+ end
114
+
115
+ # returns some basic option defaults pulled from the provided
116
+ # options hash
117
+ def uri_ref_and_root(options)
118
+ {
119
+ :request_uri => fetch_from_options(options, :uri, ''),
120
+ :request_referer => fetch_from_options(options, :referer, ''),
121
+ :rails_root => control.root
122
+ }
123
+ end
124
+
125
+ # If anything else is left over, we treat it like a custom param
126
+ def custom_params_from_opts(options)
127
+ # If anything else is left over, treat it like a custom param:
128
+ fetch_from_options(options, :custom_params, {}).merge(options)
129
+ end
130
+
131
+ # takes the request parameters out of the options hash, and
132
+ # returns them if we are capturing parameters, otherwise
133
+ # returns nil
134
+ def request_params_from_opts(options)
135
+ value = options.delete(:request_params)
136
+ if control.capture_params
137
+ value
138
+ else
139
+ nil
140
+ end
141
+ end
142
+
143
+ # normalizes the request and custom parameters before attaching
144
+ # them to the error. See NewRelic::CollectionHelper#normalize_params
145
+ def normalized_request_and_custom_params(options)
146
+ {
147
+ :request_params => normalize_params(request_params_from_opts(options)),
148
+ :custom_params => normalize_params(custom_params_from_opts(options))
149
+ }
150
+ end
151
+
152
+ # Merges together many of the options into something that can
153
+ # actually be attached to the error
154
+ def error_params_from_options(options)
155
+ uri_ref_and_root(options).merge(normalized_request_and_custom_params(options))
156
+ end
157
+
158
+ # calls a method on an object, if it responds to it - used for
159
+ # detection and soft fail-safe. Returns nil if the method does
160
+ # not exist
161
+ def sense_method(object, method)
162
+ object.send(method) if object.respond_to?(method)
163
+ end
164
+
165
+ # extracts source from the exception, if the exception supports
166
+ # that method
167
+ def extract_source(exception)
168
+ sense_method(exception, 'source_extract') if @capture_source
169
+ end
170
+
171
+ # extracts a stack trace from the exception for debugging purposes
172
+ def extract_stack_trace(exception)
173
+ actual_exception = sense_method(exception, 'original_exception') || exception
174
+ sense_method(actual_exception, 'backtrace') || '<no stack trace>'
175
+ end
176
+
177
+ # extracts a bunch of information from the exception to include
178
+ # in the noticed error - some may or may not be available, but
179
+ # we try to include all of it
180
+ def exception_info(exception)
181
+ {
182
+ :file_name => sense_method(exception, 'file_name'),
183
+ :line_number => sense_method(exception, 'line_number'),
184
+ :source => extract_source(exception),
185
+ :stack_trace => extract_stack_trace(exception)
186
+ }
187
+ end
188
+
189
+ # checks the size of the error queue to make sure we are under
190
+ # the maximum limit, and logs a warning if we are over the limit.
191
+ def over_queue_limit?(message)
192
+ over_limit = (@errors.length >= MAX_ERROR_QUEUE_LENGTH)
193
+ log.warn("The error reporting queue has reached #{MAX_ERROR_QUEUE_LENGTH}. The error detail for this and subsequent errors will not be transmitted to New Relic until the queued errors have been sent: #{message}") if over_limit
194
+ over_limit
195
+ end
196
+
197
+
198
+ # Synchronizes adding an error to the error queue, and checks if
199
+ # the error queue is too long - if so, we drop the error on the
200
+ # floor after logging a warning.
201
+ def add_to_error_queue(noticed_error)
202
+ @lock.synchronize do
203
+ @errors << noticed_error unless over_queue_limit?(noticed_error.message)
204
+ end
205
+ end
206
+ end
207
+
208
+ include NoticeError
209
+
210
+ # Notice the error with the given available options:
211
+ #
212
+ # * <tt>:uri</tt> => The request path, minus any request params or query string.
213
+ # * <tt>:referer</tt> => The URI of the referer
214
+ # * <tt>:metric</tt> => The metric name associated with the transaction
215
+ # * <tt>:request_params</tt> => Request parameters, already filtered if necessary
216
+ # * <tt>:custom_params</tt> => Custom parameters
217
+ #
218
+ # If anything is left over, it's added to custom params
219
+ # If exception is nil, the error count is bumped and no traced error is recorded
220
+ def notice_error(exception, options={})
221
+ return if should_exit_notice_error?(exception)
222
+ action_path = fetch_from_options(options, :metric, (NewRelic::Agent.instance.stats_engine.scope_name || ''))
223
+ exception_options = error_params_from_options(options).merge(exception_info(exception))
224
+ add_to_error_queue(NewRelic::NoticedError.new(action_path, exception_options, exception))
225
+ exception
226
+ rescue => e
227
+ log.error("Error capturing an error, yodawg. #{e}")
228
+ end
229
+
230
+ # Get the errors currently queued up. Unsent errors are left
231
+ # over from a previous unsuccessful attempt to send them to the server.
232
+ def harvest_errors(unsent_errors)
233
+ @lock.synchronize do
234
+ errors = @errors
235
+ @errors = []
236
+
237
+ if unsent_errors && !unsent_errors.empty?
238
+ errors = unsent_errors + errors
239
+ end
240
+
241
+ errors
242
+ end
243
+ end
244
+
245
+ private
246
+ def log
247
+ NewRelic::Agent.logger
248
+ end
249
+ end
250
+ end
251
+ end
@@ -0,0 +1,9 @@
1
+ require 'new_relic/agent'
2
+ module NewRelic
3
+ module Agent
4
+ # stub module that contains instrumentation defined in the
5
+ # instrumentation directory
6
+ module Instrumentation
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,29 @@
1
+ DependencyDetection.defer do
2
+ @name = :active_merchant
3
+
4
+ depends_on do
5
+ defined?(ActiveMerchant) && defined?(ActiveMerchant::Billing) &&
6
+ defined?(ActiveMerchant::Billing::Gateway) &&
7
+ ActiveMerchant::Billing::Gateway.respond_to?(:implementations)
8
+ end
9
+
10
+ executes do
11
+ NewRelic::Agent.logger.debug 'Installing ActiveMerchant instrumentation'
12
+ end
13
+
14
+ executes do
15
+ ActiveMerchant::Billing::Gateway.implementations.each do |gateway|
16
+ gateway.class_eval do
17
+ implemented_methods = public_instance_methods(false)
18
+ gateway_name = self.name.split('::').last
19
+ [:authorize, :purchase, :credit, :void, :capture, :recurring].each do |operation|
20
+ if implemented_methods.include?(operation.to_s)
21
+ add_method_tracer operation, "ActiveMerchant/gateway/#{gateway_name}/#{operation}", :scoped_metric_only => true
22
+ add_method_tracer operation, "ActiveMerchant/gateway/#{gateway_name}", :push_scope => false
23
+ add_method_tracer operation, "ActiveMerchant/operation/#{operation}", :push_scope => false
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,137 @@
1
+ module NewRelic
2
+ module Agent
3
+ module Instrumentation
4
+ module ActiveRecord
5
+ def self.included(instrumented_class)
6
+ instrumented_class.class_eval do
7
+ unless instrumented_class.method_defined?(:log_without_newrelic_instrumentation)
8
+ alias_method :log_without_newrelic_instrumentation, :log
9
+ alias_method :log, :log_with_newrelic_instrumentation
10
+ protected :log
11
+ end
12
+ end
13
+ end
14
+
15
+ def log_with_newrelic_instrumentation(*args, &block)
16
+ if !NewRelic::Agent.is_execution_traced?
17
+ return log_without_newrelic_instrumentation(*args, &block)
18
+ end
19
+
20
+ sql, name, binds = args
21
+ metric = metric_for_name(name) || metric_for_sql(sql)
22
+
23
+ if !metric
24
+ log_without_newrelic_instrumentation(*args, &block)
25
+ else
26
+ metrics = [metric, remote_service_metric].compact
27
+ metrics += rollup_metrics_for(metric)
28
+ self.class.trace_execution_scoped(metrics) do
29
+ t0 = Time.now
30
+ begin
31
+ log_without_newrelic_instrumentation(*args, &block)
32
+ ensure
33
+ elapsed_time = (Time.now - t0).to_f
34
+ NewRelic::Agent.instance.transaction_sampler.notice_sql(sql,
35
+ @config, elapsed_time)
36
+ NewRelic::Agent.instance.sql_sampler.notice_sql(sql, metric,
37
+ @config, elapsed_time)
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ def remote_service_metric
44
+ if @config && @config[:adapter]
45
+ type = @config[:adapter].sub(/\d*/, '')
46
+ host = @config[:host] || 'localhost'
47
+ "RemoteService/sql/#{type}/#{host}"
48
+ end
49
+ end
50
+
51
+ def metric_for_name(name)
52
+ if name && (parts = name.split " ") && parts.size == 2
53
+ model = parts.first
54
+ operation = parts.last.downcase
55
+ op_name = case operation
56
+ when 'load', 'count', 'exists' then 'find'
57
+ when 'indexes', 'columns' then nil # fall back to DirectSQL
58
+ when 'destroy', 'find', 'save', 'create' then operation
59
+ when 'update' then 'save'
60
+ else
61
+ if model == 'Join'
62
+ operation
63
+ end
64
+ end
65
+ "ActiveRecord/#{model}/#{op_name}" if op_name
66
+ end
67
+ end
68
+
69
+ def metric_for_sql(sql)
70
+ metric = NewRelic::Agent::Instrumentation::MetricFrame.database_metric_name
71
+ if metric.nil?
72
+ if sql =~ /^(select|update|insert|delete|show)/i
73
+ # Could not determine the model/operation so let's find a better
74
+ # metric. If it doesn't match the regex, it's probably a show
75
+ # command or some DDL which we'll ignore.
76
+ metric = "Database/SQL/#{$1.downcase}"
77
+ else
78
+ metric = "Database/SQL/other"
79
+ end
80
+ end
81
+ metric
82
+ end
83
+
84
+ def rollup_metrics_for(metric)
85
+ metrics = ["ActiveRecord/all"]
86
+ metrics << "ActiveRecord/#{$1}" if metric =~ /ActiveRecord\/\w+\/(\w+)/
87
+ metrics
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ DependencyDetection.defer do
95
+ @name = :active_record
96
+
97
+ depends_on do
98
+ defined?(ActiveRecord) && defined?(ActiveRecord::Base)
99
+ end
100
+
101
+ depends_on do
102
+ !NewRelic::Control.instance['skip_ar_instrumentation']
103
+ end
104
+
105
+ depends_on do
106
+ !NewRelic::Control.instance['disable_activerecord_instrumentation']
107
+ end
108
+
109
+ executes do
110
+ NewRelic::Agent.logger.debug 'Installing ActiveRecord instrumentation'
111
+ end
112
+
113
+ executes do
114
+ if defined?(::Rails) && ::Rails::VERSION::MAJOR.to_i == 3
115
+ Rails.configuration.after_initialize do
116
+ insert_instrumentation
117
+ end
118
+ else
119
+ insert_instrumentation
120
+ end
121
+ end
122
+
123
+ def insert_instrumentation
124
+ ActiveRecord::ConnectionAdapters::AbstractAdapter.module_eval do
125
+ include ::NewRelic::Agent::Instrumentation::ActiveRecord
126
+ end
127
+
128
+ ActiveRecord::Base.class_eval do
129
+ class << self
130
+ add_method_tracer(:find_by_sql, 'ActiveRecord/#{self.name}/find_by_sql',
131
+ :metric => false)
132
+ add_method_tracer(:transaction, 'ActiveRecord/#{self.name}/transaction',
133
+ :metric => false)
134
+ end
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,68 @@
1
+ module NewRelic
2
+ module Instrumentation
3
+ module ActsAsSolrInstrumentation
4
+ module ParserMethodsInstrumentation
5
+ def parse_query_with_newrelic(*args)
6
+ self.class.trace_execution_scoped(["SolrClient/ActsAsSolr/query"]) do
7
+ t0 = Time.now
8
+ begin
9
+ parse_query_without_newrelic(*args)
10
+ ensure
11
+ NewRelic::Agent.instance.transaction_sampler.notice_nosql(args.first.inspect, (Time.now - t0).to_f) rescue nil
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ DependencyDetection.defer do
21
+ @name = :acts_as_solr
22
+
23
+ depends_on do
24
+ defined?(ActsAsSolr)
25
+ end
26
+
27
+ depends_on do
28
+ defined?(ActsAsSolr::ParserMethods)
29
+ end
30
+
31
+ depends_on do
32
+ defined?(ActsAsSolr::ClassMethods)
33
+ end
34
+
35
+ depends_on do
36
+ defined?(ActsAsSolr::CommonMethods)
37
+ end
38
+
39
+ executes do
40
+ NewRelic::Agent.logger.debug 'Installing ActsAsSolr instrumentation'
41
+ end
42
+
43
+ executes do
44
+ ActsAsSolr::ParserMethods.module_eval do
45
+ include NewRelic::Instrumentation::ActsAsSolrInstrumentation::ParserMethodsInstrumentation
46
+ alias :parse_query_without_newrelic :parse_query
47
+ alias :parse_query :parse_query_with_newrelic
48
+ end
49
+ end
50
+
51
+ executes do
52
+ ActsAsSolr::ClassMethods.module_eval do
53
+ %w[find_by_solr find_id_by_solr multi_solr_search count_by_solr].each do |method|
54
+ add_method_tracer method, 'SolrClient/ActsAsSolr/query'
55
+ end
56
+ add_method_tracer :rebuild_solr_index, 'SolrClient/ActsAsSolr/index'
57
+ end
58
+ end
59
+
60
+ executes do
61
+ ActsAsSolr::CommonMethods.module_eval do
62
+ add_method_tracer :solr_add, 'SolrClient/ActsAsSolr/add'
63
+ add_method_tracer :solr_delete, 'SolrClient/ActsAsSolr/delete'
64
+ add_method_tracer :solr_commit, 'SolrClient/ActsAsSolr/commit'
65
+ add_method_tracer :solr_optimize, 'SolrClient/ActsAsSolr/optimize'
66
+ end
67
+ end
68
+ end