newrelic_rpm 2.10.6 → 2.10.8

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of newrelic_rpm might be problematic. Click here for more details.

Files changed (220) hide show
  1. data/CHANGELOG +14 -0
  2. data/lib/new_relic/agent.rb +5 -4
  3. data/lib/new_relic/agent/agent.rb +81 -101
  4. data/lib/new_relic/agent/error_collector.rb +1 -2
  5. data/lib/new_relic/agent/instrumentation/authlogic.rb +2 -2
  6. data/lib/new_relic/agent/instrumentation/merb/controller.rb +2 -2
  7. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +45 -0
  8. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +21 -0
  9. data/lib/new_relic/agent/method_tracer.rb +2 -2
  10. data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +1 -1
  11. data/lib/new_relic/agent/stats_engine/samplers.rb +1 -2
  12. data/lib/new_relic/agent/transaction_sampler.rb +1 -1
  13. data/lib/new_relic/agent/worker_loop.rb +47 -86
  14. data/lib/new_relic/{agent/collection_helper.rb → collection_helper.rb} +2 -4
  15. data/lib/new_relic/control.rb +18 -2
  16. data/lib/new_relic/control/rails3.rb +75 -0
  17. data/lib/new_relic/local_environment.rb +11 -3
  18. data/lib/new_relic/noticed_error.rb +2 -1
  19. data/lib/new_relic/version.rb +10 -9
  20. data/newrelic_rpm.gemspec +195 -3
  21. data/rdoc/classes/NewRelic.html +293 -0
  22. data/rdoc/classes/NewRelic/Agent.html +810 -0
  23. data/rdoc/classes/NewRelic/Agent/Agent.html +742 -0
  24. data/rdoc/classes/NewRelic/Agent/BackgroundLoadingError.html +111 -0
  25. data/rdoc/classes/NewRelic/Agent/BusyCalculator.html +309 -0
  26. data/rdoc/classes/NewRelic/Agent/CollectionHelper.html +196 -0
  27. data/rdoc/classes/NewRelic/Agent/ErrorCollector.html +378 -0
  28. data/rdoc/classes/NewRelic/Agent/ForceDisconnectException.html +118 -0
  29. data/rdoc/classes/NewRelic/Agent/ForceRestartException.html +117 -0
  30. data/rdoc/classes/NewRelic/Agent/IgnoreSilentlyException.html +118 -0
  31. data/rdoc/classes/NewRelic/Agent/Instrumentation.html +174 -0
  32. data/rdoc/classes/NewRelic/Agent/Instrumentation/ActiveRecordInstrumentation.html +221 -0
  33. data/rdoc/classes/NewRelic/Agent/Instrumentation/ControllerInstrumentation.html +349 -0
  34. data/rdoc/classes/NewRelic/Agent/Instrumentation/ControllerInstrumentation/ClassMethods.html +277 -0
  35. data/rdoc/classes/NewRelic/Agent/Instrumentation/DelayedJobInstrumentation.html +112 -0
  36. data/rdoc/classes/NewRelic/Agent/Instrumentation/MetricFrame.html +1007 -0
  37. data/rdoc/classes/NewRelic/Agent/Instrumentation/Rack.html +321 -0
  38. data/rdoc/classes/NewRelic/Agent/Instrumentation/Sinatra.html +176 -0
  39. data/rdoc/classes/NewRelic/Agent/LicenseException.html +117 -0
  40. data/rdoc/classes/NewRelic/Agent/MethodTracer.html +150 -0
  41. data/rdoc/classes/NewRelic/Agent/MethodTracer/ClassMethods.html +295 -0
  42. data/rdoc/classes/NewRelic/Agent/MethodTracer/InstanceMethods.html +284 -0
  43. data/rdoc/classes/NewRelic/Agent/PostTooBigException.html +120 -0
  44. data/rdoc/classes/NewRelic/Agent/Sampler.html +314 -0
  45. data/rdoc/classes/NewRelic/Agent/Sampler/Unsupported.html +117 -0
  46. data/rdoc/classes/NewRelic/Agent/Samplers.html +126 -0
  47. data/rdoc/classes/NewRelic/Agent/Samplers/CpuSampler.html +327 -0
  48. data/rdoc/classes/NewRelic/Agent/Samplers/DelayedJobLockSampler.html +296 -0
  49. data/rdoc/classes/NewRelic/Agent/Samplers/MemorySampler.html +321 -0
  50. data/rdoc/classes/NewRelic/Agent/Samplers/MemorySampler/Base.html +186 -0
  51. data/rdoc/classes/NewRelic/Agent/Samplers/MemorySampler/JavaHeapSampler.html +173 -0
  52. data/rdoc/classes/NewRelic/Agent/Samplers/MemorySampler/ProcStatus.html +216 -0
  53. data/rdoc/classes/NewRelic/Agent/Samplers/MemorySampler/ShellPS.html +207 -0
  54. data/rdoc/classes/NewRelic/Agent/Samplers/ObjectSampler.html +222 -0
  55. data/rdoc/classes/NewRelic/Agent/ServerError.html +117 -0
  56. data/rdoc/classes/NewRelic/Agent/ShimAgent.html +297 -0
  57. data/rdoc/classes/NewRelic/Agent/StatsEngine.html +204 -0
  58. data/rdoc/classes/NewRelic/Agent/StatsEngine/MetricStats.html +441 -0
  59. data/rdoc/classes/NewRelic/Agent/StatsEngine/Samplers.html +237 -0
  60. data/rdoc/classes/NewRelic/Agent/StatsEngine/ScopeStackElement.html +178 -0
  61. data/rdoc/classes/NewRelic/Agent/StatsEngine/Transactions.html +385 -0
  62. data/rdoc/classes/NewRelic/Agent/TransactionSampleBuilder.html +505 -0
  63. data/rdoc/classes/NewRelic/Agent/TransactionSampler.html +690 -0
  64. data/rdoc/classes/NewRelic/Agent/WorkerLoop.html +305 -0
  65. data/rdoc/classes/NewRelic/Agent/WorkerLoop/LoopTask.html +224 -0
  66. data/rdoc/classes/NewRelic/ApdexStats.html +196 -0
  67. data/rdoc/classes/NewRelic/BasicStats.html +113 -0
  68. data/rdoc/classes/NewRelic/ChainedCall.html +180 -0
  69. data/rdoc/classes/NewRelic/Commands.html +112 -0
  70. data/rdoc/classes/NewRelic/Commands/CommandFailure.html +167 -0
  71. data/rdoc/classes/NewRelic/Commands/Deployments.html +285 -0
  72. data/rdoc/classes/NewRelic/Control.html +1760 -0
  73. data/rdoc/classes/NewRelic/Control/External.html +148 -0
  74. data/rdoc/classes/NewRelic/Control/Merb.html +227 -0
  75. data/rdoc/classes/NewRelic/Control/Rails.html +542 -0
  76. data/rdoc/classes/NewRelic/Control/Ruby.html +266 -0
  77. data/rdoc/classes/NewRelic/Control/Sinatra.html +178 -0
  78. data/rdoc/classes/NewRelic/DelayedJobInjection.html +118 -0
  79. data/rdoc/classes/NewRelic/Histogram.html +226 -0
  80. data/rdoc/classes/NewRelic/Histogram/Bucket.html +319 -0
  81. data/rdoc/classes/NewRelic/Histogram/Shim.html +144 -0
  82. data/rdoc/classes/NewRelic/LocalEnvironment.html +572 -0
  83. data/rdoc/classes/NewRelic/MerbBootLoader.html +146 -0
  84. data/rdoc/classes/NewRelic/MethodTraceStats.html +250 -0
  85. data/rdoc/classes/NewRelic/MetricData.html +347 -0
  86. data/rdoc/classes/NewRelic/MetricParser.html +747 -0
  87. data/rdoc/classes/NewRelic/MetricParser/ActionMailer.html +170 -0
  88. data/rdoc/classes/NewRelic/MetricParser/ActiveMerchant.html +267 -0
  89. data/rdoc/classes/NewRelic/MetricParser/ActiveRecord.html +250 -0
  90. data/rdoc/classes/NewRelic/MetricParser/Controller.html +363 -0
  91. data/rdoc/classes/NewRelic/MetricParser/ControllerCPU.html +319 -0
  92. data/rdoc/classes/NewRelic/MetricParser/Errors.html +170 -0
  93. data/rdoc/classes/NewRelic/MetricParser/External.html +339 -0
  94. data/rdoc/classes/NewRelic/MetricParser/MemCache.html +340 -0
  95. data/rdoc/classes/NewRelic/MetricParser/OtherTransaction.html +205 -0
  96. data/rdoc/classes/NewRelic/MetricParser/View.html +381 -0
  97. data/rdoc/classes/NewRelic/MetricParser/WebFrontend.html +182 -0
  98. data/rdoc/classes/NewRelic/MetricParser/WebService.html +172 -0
  99. data/rdoc/classes/NewRelic/MetricSpec.html +406 -0
  100. data/rdoc/classes/NewRelic/Metrics.html +138 -0
  101. data/rdoc/classes/NewRelic/NoticedError.html +200 -0
  102. data/rdoc/classes/NewRelic/Rack.html +112 -0
  103. data/rdoc/classes/NewRelic/Rack/MetricApp.html +193 -0
  104. data/rdoc/classes/NewRelic/Rack/Status.html +165 -0
  105. data/rdoc/classes/NewRelic/ScopedMethodTraceStats.html +225 -0
  106. data/rdoc/classes/NewRelic/Stats.html +917 -0
  107. data/rdoc/classes/NewRelic/StatsBase.html +346 -0
  108. data/rdoc/classes/NewRelic/TransactionAnalysis.html +269 -0
  109. data/rdoc/classes/NewRelic/TransactionAnalysis/SegmentSummary.html +338 -0
  110. data/rdoc/classes/NewRelic/TransactionSample.html +766 -0
  111. data/rdoc/classes/NewRelic/TransactionSample/CompositeSegment.html +195 -0
  112. data/rdoc/classes/NewRelic/TransactionSample/FakeSegment.html +113 -0
  113. data/rdoc/classes/NewRelic/TransactionSample/IDGenerator.html +178 -0
  114. data/rdoc/classes/NewRelic/TransactionSample/Segment.html +920 -0
  115. data/rdoc/classes/NewRelic/TransactionSample/SummarySegment.html +180 -0
  116. data/rdoc/classes/NewRelic/VersionNumber.html +338 -0
  117. data/rdoc/classes/NewRelicApi.html +270 -0
  118. data/rdoc/classes/NewRelicApi/Account.html +178 -0
  119. data/rdoc/classes/NewRelicApi/Account/AccountUsage.html +111 -0
  120. data/rdoc/classes/NewRelicApi/Account/AccountView.html +146 -0
  121. data/rdoc/classes/NewRelicApi/Application.html +139 -0
  122. data/rdoc/classes/NewRelicApi/Application/Agent.html +119 -0
  123. data/rdoc/classes/NewRelicApi/Deployment.html +123 -0
  124. data/rdoc/classes/NewRelicApi/Subscription.html +111 -0
  125. data/rdoc/classes/NewRelicApi/ThresholdValue.html +174 -0
  126. data/rdoc/classes/NewRelicApi/User.html +111 -0
  127. data/rdoc/created.rid +1 -0
  128. data/rdoc/files/CHANGELOG.html +649 -0
  129. data/rdoc/files/LICENSE.html +143 -0
  130. data/rdoc/files/lib/new_relic/agent/agent_rb.html +113 -0
  131. data/rdoc/files/lib/new_relic/agent/busy_calculator_rb.html +115 -0
  132. data/rdoc/files/lib/new_relic/agent/chained_call_rb.html +107 -0
  133. data/rdoc/files/lib/new_relic/agent/collection_helper_rb.html +101 -0
  134. data/rdoc/files/lib/new_relic/agent/error_collector_rb.html +101 -0
  135. data/rdoc/files/lib/new_relic/agent/instrumentation/active_merchant_rb.html +107 -0
  136. data/rdoc/files/lib/new_relic/agent/instrumentation/active_record_instrumentation_rb.html +108 -0
  137. data/rdoc/files/lib/new_relic/agent/instrumentation/authlogic_rb.html +101 -0
  138. data/rdoc/files/lib/new_relic/agent/instrumentation/controller_instrumentation_rb.html +108 -0
  139. data/rdoc/files/lib/new_relic/agent/instrumentation/data_mapper_rb.html +191 -0
  140. data/rdoc/files/lib/new_relic/agent/instrumentation/delayed_job_instrumentation_rb.html +109 -0
  141. data/rdoc/files/lib/new_relic/agent/instrumentation/memcache_rb.html +152 -0
  142. data/rdoc/files/lib/new_relic/agent/instrumentation/merb/controller_rb.html +155 -0
  143. data/rdoc/files/lib/new_relic/agent/instrumentation/merb/errors_rb.html +107 -0
  144. data/rdoc/files/lib/new_relic/agent/instrumentation/metric_frame_rb.html +113 -0
  145. data/rdoc/files/lib/new_relic/agent/instrumentation/net_rb.html +172 -0
  146. data/rdoc/files/lib/new_relic/agent/instrumentation/passenger_instrumentation_rb.html +101 -0
  147. data/rdoc/files/lib/new_relic/agent/instrumentation/rack_rb.html +108 -0
  148. data/rdoc/files/lib/new_relic/agent/instrumentation/rails/action_controller_rb.html +152 -0
  149. data/rdoc/files/lib/new_relic/agent/instrumentation/rails/action_web_service_rb.html +108 -0
  150. data/rdoc/files/lib/new_relic/agent/instrumentation/rails/errors_rb.html +167 -0
  151. data/rdoc/files/lib/new_relic/agent/instrumentation/sinatra_rb.html +108 -0
  152. data/rdoc/files/lib/new_relic/agent/method_tracer_rb.html +108 -0
  153. data/rdoc/files/lib/new_relic/agent/sampler_rb.html +116 -0
  154. data/rdoc/files/lib/new_relic/agent/samplers/cpu_sampler_rb.html +101 -0
  155. data/rdoc/files/lib/new_relic/agent/samplers/delayed_job_lock_sampler_rb.html +101 -0
  156. data/rdoc/files/lib/new_relic/agent/samplers/memory_sampler_rb.html +101 -0
  157. data/rdoc/files/lib/new_relic/agent/samplers/object_sampler_rb.html +101 -0
  158. data/rdoc/files/lib/new_relic/agent/shim_agent_rb.html +108 -0
  159. data/rdoc/files/lib/new_relic/agent/stats_engine/metric_stats_rb.html +101 -0
  160. data/rdoc/files/lib/new_relic/agent/stats_engine/samplers_rb.html +101 -0
  161. data/rdoc/files/lib/new_relic/agent/stats_engine/transactions_rb.html +101 -0
  162. data/rdoc/files/lib/new_relic/agent/stats_engine_rb.html +110 -0
  163. data/rdoc/files/lib/new_relic/agent/transaction_sampler_rb.html +101 -0
  164. data/rdoc/files/lib/new_relic/agent/worker_loop_rb.html +101 -0
  165. data/rdoc/files/lib/new_relic/agent_rb.html +204 -0
  166. data/rdoc/files/lib/new_relic/commands/deployments_rb.html +119 -0
  167. data/rdoc/files/lib/new_relic/commands/new_relic_commands_rb.html +108 -0
  168. data/rdoc/files/lib/new_relic/control/external_rb.html +117 -0
  169. data/rdoc/files/lib/new_relic/control/merb_rb.html +101 -0
  170. data/rdoc/files/lib/new_relic/control/rails_rb.html +108 -0
  171. data/rdoc/files/lib/new_relic/control/ruby_rb.html +110 -0
  172. data/rdoc/files/lib/new_relic/control/sinatra_rb.html +108 -0
  173. data/rdoc/files/lib/new_relic/control_rb.html +116 -0
  174. data/rdoc/files/lib/new_relic/delayed_job_injection_rb.html +180 -0
  175. data/rdoc/files/lib/new_relic/histogram_rb.html +114 -0
  176. data/rdoc/files/lib/new_relic/local_environment_rb.html +111 -0
  177. data/rdoc/files/lib/new_relic/merbtasks_rb.html +101 -0
  178. data/rdoc/files/lib/new_relic/metric_data_rb.html +101 -0
  179. data/rdoc/files/lib/new_relic/metric_parser/action_mailer_rb.html +101 -0
  180. data/rdoc/files/lib/new_relic/metric_parser/active_merchant_rb.html +101 -0
  181. data/rdoc/files/lib/new_relic/metric_parser/active_record_rb.html +101 -0
  182. data/rdoc/files/lib/new_relic/metric_parser/controller_cpu_rb.html +101 -0
  183. data/rdoc/files/lib/new_relic/metric_parser/controller_rb.html +101 -0
  184. data/rdoc/files/lib/new_relic/metric_parser/errors_rb.html +101 -0
  185. data/rdoc/files/lib/new_relic/metric_parser/external_rb.html +101 -0
  186. data/rdoc/files/lib/new_relic/metric_parser/mem_cache_rb.html +101 -0
  187. data/rdoc/files/lib/new_relic/metric_parser/other_transaction_rb.html +108 -0
  188. data/rdoc/files/lib/new_relic/metric_parser/view_rb.html +101 -0
  189. data/rdoc/files/lib/new_relic/metric_parser/web_frontend_rb.html +107 -0
  190. data/rdoc/files/lib/new_relic/metric_parser/web_service_rb.html +101 -0
  191. data/rdoc/files/lib/new_relic/metric_parser_rb.html +101 -0
  192. data/rdoc/files/lib/new_relic/metric_spec_rb.html +108 -0
  193. data/rdoc/files/lib/new_relic/metrics_rb.html +101 -0
  194. data/rdoc/files/lib/new_relic/noticed_error_rb.html +107 -0
  195. data/rdoc/files/lib/new_relic/rack/metric_app_rb.html +108 -0
  196. data/rdoc/files/lib/new_relic/rack_app_rb.html +110 -0
  197. data/rdoc/files/lib/new_relic/recipes_rb.html +128 -0
  198. data/rdoc/files/lib/new_relic/stats_rb.html +101 -0
  199. data/rdoc/files/lib/new_relic/transaction_analysis_rb.html +108 -0
  200. data/rdoc/files/lib/new_relic/transaction_sample_rb.html +101 -0
  201. data/rdoc/files/lib/new_relic/version_rb.html +101 -0
  202. data/rdoc/files/lib/new_relic_api_rb.html +145 -0
  203. data/rdoc/files/lib/newrelic_rpm_rb.html +147 -0
  204. data/rdoc/files/lib/tasks/all_rb.html +107 -0
  205. data/rdoc/fr_class_index.html +134 -0
  206. data/rdoc/fr_file_index.html +103 -0
  207. data/rdoc/fr_method_index.html +568 -0
  208. data/rdoc/index.html +24 -0
  209. data/rdoc/rdoc-style.css +208 -0
  210. data/test/new_relic/agent/active_record_instrumentation_test.rb +16 -5
  211. data/test/new_relic/agent/collection_helper_test.rb +1 -1
  212. data/test/new_relic/agent/error_collector_test.rb +2 -4
  213. data/test/new_relic/agent/rpm_agent_test.rb +1 -1
  214. data/test/new_relic/agent/task_instrumentation_test.rb +1 -1
  215. data/test/new_relic/agent/worker_loop_test.rb +33 -76
  216. data/test/new_relic/control_test.rb +9 -2
  217. data/test/new_relic/stats_test.rb +29 -1
  218. data/test/new_relic/version_number_test.rb +13 -0
  219. data/ui/helpers/newrelic_helper.rb +1 -2
  220. metadata +196 -4
@@ -0,0 +1,21 @@
1
+ module NewRelic
2
+ module Agent
3
+ module Instrumentation
4
+ module Rails3
5
+ module Errors
6
+ def newrelic_notice_error(exception, custom_params = {})
7
+ filtered_params = (respond_to? :filter_parameters) ? filter_parameters(params) : params
8
+ filtered_params.merge!(custom_params)
9
+ NewRelic::Agent.agent.error_collector.notice_error(exception, request, newrelic_metric_path, filtered_params)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ if defined?(ActionController) && defined?(ActionController::Base)
18
+ class ActionController::Base
19
+ include NewRelic::Agent::Instrumentation::Rails3::Errors
20
+ end
21
+ end
@@ -23,12 +23,12 @@ module Agent
23
23
  # To instrument a class method:
24
24
  #
25
25
  # require 'new_relic/agent/method_tracer'
26
- # class A
27
- # extend NewRelic::Agent::MethodTracer
26
+ # class An
28
27
  # def self.process
29
28
  # ...
30
29
  # end
31
30
  # class << self
31
+ # include NewRelic::Agent::MethodTracer
32
32
  # add_method_tracer :process
33
33
  # end
34
34
  # end
@@ -5,7 +5,7 @@ module NewRelic
5
5
  def initialize
6
6
  super :delayed_job_lock
7
7
  raise Unsupported, "DJ instrumentation disabled" if NewRelic::Control.instance['disable_dj']
8
- raise Unsupported, "No DJ worker present" if NewRelic::DelayedJobInjection.worker_name
8
+ raise Unsupported, "No DJ worker present" unless NewRelic::DelayedJobInjection.worker_name
9
9
  end
10
10
 
11
11
  def stats
@@ -16,7 +16,7 @@ module Agent
16
16
 
17
17
  def spawn_sampler_thread
18
18
 
19
- return if !@sampler_process.nil? && @sampler_process == $$
19
+ return if @sampler_thread && @sampler_thread.alive?
20
20
 
21
21
  # start up a thread that will periodically poll for metric samples
22
22
  return if periodic_samplers.empty?
@@ -30,7 +30,6 @@ module Agent
30
30
  end
31
31
  end
32
32
  @sampler_thread['newrelic_label'] = 'Sampler Tasks'
33
- @sampler_process = $$
34
33
  end
35
34
 
36
35
  # Add an instance of Sampler to be invoked about every 10 seconds on a background
@@ -223,7 +223,7 @@ module Agent
223
223
  class TransactionSampleBuilder
224
224
  attr_reader :current_segment, :sample
225
225
 
226
- include CollectionHelper
226
+ include NewRelic::CollectionHelper
227
227
 
228
228
  def initialize(time=nil)
229
229
  time ||= Time.now.to_f
@@ -1,78 +1,57 @@
1
+ require 'thread'
1
2
  module NewRelic
2
- module Agent
3
-
4
- # A worker loop executes a set of registered tasks on a single thread.
5
- # A task is a proc or block with a specified call period in seconds.
6
- class WorkerLoop
3
+ module Agent
7
4
 
8
- attr_reader :log
9
- attr_reader :pid
10
-
11
- def initialize(log = Logger.new(STDERR))
12
- @tasks = []
13
- @log = log
14
- @should_run = true
15
- @pid = $$
16
- end
17
-
18
- # Run infinitely, calling the registered tasks at their specified
19
- # call periods. The caller is responsible for creating the thread
20
- # that runs this worker loop
21
- def run
22
- while keep_running do
23
- run_next_task
5
+ # A worker loop executes a set of registered tasks on a single thread.
6
+ # A task is a proc or block with a specified call period in seconds.
7
+ class WorkerLoop
8
+
9
+ def initialize
10
+ @log = log
11
+ @should_run = true
24
12
  end
25
- end
26
-
27
- def keep_running
28
- @should_run && (@pid == $$)
29
- end
30
-
31
- def stop
32
- @should_run = false
33
- end
34
-
35
- MIN_CALL_PERIOD = 0.1
36
-
37
- # add a task to the worker loop. The task will be called approximately once
38
- # every call_period seconds. The task is passed as a block
39
- def add_task(call_period, desc="", &task_proc)
40
- if call_period < MIN_CALL_PERIOD
41
- raise ArgumentError, "Invalid Call Period (must be > #{MIN_CALL_PERIOD}): #{call_period}"
13
+
14
+ def lock
15
+ @@lock ||= Mutex.new
42
16
  end
43
- @tasks << LoopTask.new(call_period, desc, &task_proc)
44
- end
45
-
46
- private
47
- def next_task
48
- @tasks.inject do |soonest, task|
49
- (task.next_invocation_time < soonest.next_invocation_time) ? task : soonest
17
+
18
+ def log
19
+ NewRelic::Control.instance.log
50
20
  end
51
- end
52
-
53
- def run_next_task
54
- if @tasks.empty?
55
- sleep 5.0
56
- return
21
+ # Run infinitely, calling the registered tasks at their specified
22
+ # call periods. The caller is responsible for creating the thread
23
+ # that runs this worker loop
24
+ def run(period, &block)
25
+ @period = period
26
+ @next_invocation_time = Time.now + @period
27
+ @task = block
28
+ while keep_running do
29
+ now = Time.now
30
+ while now < @next_invocation_time
31
+ # sleep until this next task's scheduled invocation time
32
+ sleep_time = @next_invocation_time - now
33
+ sleep sleep_time if sleep_time > 0
34
+ now = Time.now
35
+ end
36
+ run_task if keep_running
37
+ end
57
38
  end
58
39
 
59
- # get the next task to be executed, which is the task with the lowest (ie, soonest)
60
- # next invocation time.
61
- task = next_task
40
+ def keep_running
41
+ @should_run
42
+ end
62
43
 
63
- while Time.now < task.next_invocation_time
64
-
65
- # sleep until this next task's scheduled invocation time
66
- sleep_time = task.next_invocation_time - Time.now
67
- sleep sleep_time if sleep_time > 0
68
- return if !keep_running
44
+ def stop
45
+ @should_run = false
69
46
  end
70
47
 
71
- begin
72
- task.execute if keep_running
48
+ def run_task
49
+ lock.synchronize do
50
+ @task.call
51
+ end
73
52
  rescue ServerError => e
74
53
  log.debug "Server Error: #{e}"
75
- rescue NewRelic::Agent::ForceRestartException => e
54
+ rescue NewRelic::Agent::ForceRestartException, NewRelic::Agent::ForceDisconnectException
76
55
  # blow out the loop
77
56
  raise
78
57
  rescue RuntimeError => e
@@ -86,34 +65,16 @@ module Agent
86
65
  log.debug message
87
66
  log.debug e.backtrace.join("\n")
88
67
  end
89
- rescue Timeout::Error, NewRelic::Agent::IgnoreSilentlyException
68
+ rescue Timeout::Error, NewRelic::Agent::ServerConnectionException
90
69
  # Want to ignore these because they are handled already
91
70
  rescue ScriptError, StandardError => e
92
71
  log.error "Error running task in Agent Worker Loop '#{e}': #{e.backtrace.first}"
93
72
  log.debug e.backtrace.join("\n")
94
- end
95
- end
96
-
97
- class LoopTask
98
-
99
- def initialize(call_period, desc="", &task_proc)
100
- @call_period = call_period
101
- @last_invocation_time = Time.now
102
- @task = task_proc
103
- @desc = desc
104
- end
105
- def to_s
106
- "Task[#{@desc}]"
107
- end
108
- def next_invocation_time
109
- @last_invocation_time + @call_period
110
- end
111
-
112
- def execute
113
- @last_invocation_time = Time.now
114
- @task.call
73
+ ensure
74
+ while @next_invocation_time < Time.now
75
+ @next_invocation_time += @period
76
+ end
115
77
  end
116
78
  end
117
79
  end
118
80
  end
119
- end
@@ -1,6 +1,5 @@
1
1
  module NewRelic
2
- module Agent
3
- module CollectionHelper
2
+ module CollectionHelper
4
3
  # Transform parameter hash into a hash whose values are strictly
5
4
  # strings
6
5
  def normalize_params(params)
@@ -65,6 +64,5 @@ module NewRelic
65
64
  truncate(flatten(string), len)
66
65
  end
67
66
  end
68
- end
69
- end
67
+ end
70
68
  end
@@ -87,8 +87,8 @@ module NewRelic
87
87
  # between calling init_plugin the first time and the second time, the env
88
88
  # has been overridden
89
89
  @settings = nil
90
-
91
- options.each { |sym, val | self[sym.to_s] = val unless sym == :config }
90
+ settings
91
+ merge_options(options)
92
92
  if logger_override
93
93
  @log = logger_override
94
94
  # Try to grab the log filename
@@ -482,6 +482,22 @@ module NewRelic
482
482
  self.class.newrelic_root
483
483
  end
484
484
 
485
+ # Merge the given options into the config options.
486
+ # They might be a nested hash
487
+ def merge_options(options, hash=self)
488
+ options.each do |key, val |
489
+ case
490
+ when key == :config then next
491
+ when val.is_a?(Hash)
492
+ merge_options(val, hash[key.to_s] ||= {})
493
+ when val.nil?
494
+ hash.delete(key.to_s)
495
+ else
496
+ hash[key.to_s] = val
497
+ end
498
+ end
499
+ end
500
+
485
501
  def load_instrumentation_files pattern
486
502
  Dir.glob(pattern) do |file|
487
503
  begin
@@ -0,0 +1,75 @@
1
+ # Control subclass instantiated when Rails is detected. Contains
2
+ # Rails specific configuration, instrumentation, environment values,
3
+ # etc.
4
+ class NewRelic::Control::Rails3 < NewRelic::Control
5
+
6
+ def env
7
+ @env ||= ::Rails.env.to_s
8
+ end
9
+
10
+ def root
11
+ @root ||= Rails.root.to_s
12
+ end
13
+
14
+ def logger
15
+ ::Rails.logger
16
+ end
17
+
18
+ def base_log_file
19
+ logger.instance_eval {
20
+ @log.path
21
+ }
22
+ rescue
23
+ File.join(root, 'log')
24
+ end
25
+ private :base_log_file
26
+
27
+ def log_path
28
+ @log_path ||= File.expand_path(File.dirname(base_log_file))
29
+ end
30
+
31
+ def vendor_root
32
+ @vendor_root ||= File.join(root,'vendor','rails')
33
+ end
34
+
35
+ def version
36
+ @rails_version ||= NewRelic::VersionNumber.new(::Rails::VERSION::STRING)
37
+ end
38
+
39
+ def init_config(options={})
40
+ rails_config=options[:config]
41
+ if !agent_enabled?
42
+ # Might not be running if it does not think mongrel, thin, passenger, etc
43
+ # is running, if it things it's a rake task, or if the agent_enabled is false.
44
+ logger.info "New Relic Agent not running."
45
+ else
46
+ logger.info "Starting the New Relic Agent."
47
+ end
48
+ end
49
+
50
+ protected
51
+
52
+ # Collect the Rails::Info into an associative array as well as the list of plugins
53
+ def append_environment_info
54
+ local_env.append_environment_value('Rails version'){ version }
55
+ local_env.append_environment_value('Rails threadsafe') do
56
+ ::Rails.configuration.action_controller.allow_concurrency == true
57
+ end
58
+ local_env.append_environment_value('Rails Env') { env }
59
+ local_env.append_gem_list do
60
+ ::Rails.configuration.gems.map do | gem |
61
+ version = (gem.respond_to?(:version) && gem.version) ||
62
+ (gem.specification.respond_to?(:version) && gem.specification.version)
63
+ gem.name + (version ? "(#{version})" : "")
64
+ end
65
+ end
66
+ local_env.append_plugin_list { ::Rails.configuration.plugins }
67
+ end
68
+
69
+ def install_shim
70
+ super
71
+ require 'new_relic/agent/instrumentation/controller_instrumentation'
72
+ ActionController::Base.send :include, NewRelic::Agent::Instrumentation::ControllerInstrumentation::Shim
73
+ end
74
+
75
+ end
@@ -5,7 +5,7 @@ module NewRelic
5
5
  # An instance of LocalEnvironment is responsible for determining
6
6
  # three things:
7
7
  #
8
- # * Framework - :rails, :merb, :ruby, :external, :test
8
+ # * Framework - :rails, :rails3, :merb, :ruby, :external, :test
9
9
  # * Dispatcher - A supported dispatcher, or nil (:mongrel, :thin, :passenger, :webrick, etc)
10
10
  # * Dispatcher Instance ID, which distinguishes agents on a single host from each other
11
11
  #
@@ -17,7 +17,7 @@ module NewRelic
17
17
 
18
18
  attr_accessor :dispatcher # mongrel, thin, webrick, or possibly nil
19
19
  attr_accessor :dispatcher_instance_id # used to distinguish instances of a dispatcher from each other, may be nil
20
- attr_accessor :framework # rails, merb, external, ruby, test
20
+ attr_accessor :framework # rails, rails3, merb, external, ruby, test
21
21
  attr_reader :mongrel # The mongrel instance, if there is one, captured as a convenience
22
22
  attr_reader :processors # The number of cpus, if detected, or nil
23
23
  alias environment dispatcher
@@ -179,13 +179,21 @@ module NewRelic
179
179
  when ENV['NEWRELIC_FRAMEWORK'] then ENV['NEWRELIC_FRAMEWORK'].to_sym
180
180
  when defined?(::NewRelic::TEST) then :test
181
181
  when defined?(::Merb) && defined?(::Merb::Plugins) then :merb
182
- when defined?(::Rails) then :rails
182
+ when defined?(::Rails) then check_rails_version
183
183
  when defined?(::Sinatra) && defined?(::Sinatra::Base) then :sinatra
184
184
  when defined?(::NewRelic::IA) then :external
185
185
  else :ruby
186
186
  end
187
187
  end
188
188
 
189
+ def check_rails_version
190
+ if Rails::VERSION::MAJOR < 3
191
+ :rails
192
+ else
193
+ :rails3
194
+ end
195
+ end
196
+
189
197
  def check_for_torquebox
190
198
  return unless defined?(::JRuby) &&
191
199
  ( Java::OrgTorqueboxRailsWebDeployers::RailsRackDeployer rescue nil)
@@ -1,10 +1,11 @@
1
1
  # This class encapsulates an error that was noticed by RPM in a managed app.
2
2
  class NewRelic::NoticedError
3
+ extend NewRelic::CollectionHelper
3
4
  attr_accessor :path, :timestamp, :params, :exception_class, :message
4
5
 
5
6
  def initialize(path, data, exception, timestamp = Time.now)
6
7
  self.path = path
7
- self.params = data
8
+ self.params = NewRelic::NoticedError.normalize_params(data)
8
9
 
9
10
  self.exception_class = exception ? exception.class.name : '<no exception>'
10
11
 
@@ -3,9 +3,9 @@ module NewRelic
3
3
  module VERSION #:nodoc:
4
4
  MAJOR = 2
5
5
  MINOR = 10
6
- TINY = 6
7
- EXPERIMENTAL = nil
8
- STRING = [MAJOR, MINOR, TINY, EXPERIMENTAL].compact.join('.')
6
+ TINY = 8
7
+ BUILD = nil # Set to nil for a release, 'beta1', 'alpha', etc for prerelease builds
8
+ STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
9
9
  end
10
10
 
11
11
  # Helper class for managing version comparisons
@@ -14,7 +14,7 @@ module NewRelic
14
14
  include Comparable
15
15
  def initialize(version_string)
16
16
  version_string ||= '1.0.0'
17
- @parts = version_string.split('.').map{|n| n.to_i }
17
+ @parts = version_string.split('.').map{|n| n =~ /^\d+$/ ? n.to_i : n}
18
18
  end
19
19
  def major_version; @parts[0]; end
20
20
  def minor_version; @parts[1]; end
@@ -42,11 +42,12 @@ module NewRelic
42
42
  a, b = parts1.first, parts2.first
43
43
  case
44
44
  when a.nil? && b.nil? then 0
45
- when a.nil? then -1
46
- when b.nil? then 1
47
- when a == b
48
- compare(parts1[1..-1], parts2[1..-1])
49
- else
45
+ when a.nil? then b.is_a?(Fixnum) ? -1 : 1
46
+ when b.nil? then -compare(parts2, parts1)
47
+ when a.to_s == b.to_s then compare(parts1[1..-1], parts2[1..-1])
48
+ when a.is_a?(String) then b.is_a?(Fixnum) ? -1 : (a <=> b)
49
+ when b.is_a?(String) then -compare(parts2, parts1)
50
+ else # they are both fixnums, not nil
50
51
  a <=> b
51
52
  end
52
53
  end