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
data/CHANGELOG CHANGED
@@ -1,3 +1,17 @@
1
+ v2.10.8
2
+ * fix bug in delayed_job instrumentation that caused the job queue sampler
3
+ to run in the wrong place
4
+ * change startup sequence and code that restarts the worker loop
5
+ thread
6
+ * detect the unicorn master and dont start the agent
7
+ * fix problem with the Authlogic metric names which caused errors in
8
+ developer mode. Authlogic metrics now adhere to the convention of
9
+ prefixing the name with 'Custom'
10
+ * allow more correct overriding of transaction trace settings in the
11
+ call to #manual_start
12
+ * simplify WorkerLoop and add better protection for concurrency
13
+ * preliminary support for rails3
14
+
1
15
  v2.10.6
2
16
  * fix missing URL and referer on some traced errors and transactions
3
17
  * gather traced errors *after* executing the rescue chain in ActionController
@@ -75,7 +75,8 @@ module NewRelic
75
75
  # support at New Relic for help.
76
76
  module Agent
77
77
  extend self
78
-
78
+
79
+
79
80
  require 'new_relic/version'
80
81
  require 'new_relic/local_environment'
81
82
  require 'new_relic/stats'
@@ -84,6 +85,7 @@ module NewRelic
84
85
  require 'new_relic/metric_spec'
85
86
  require 'new_relic/metric_data'
86
87
  require 'new_relic/metric_parser'
88
+ require 'new_relic/collection_helper'
87
89
  require 'new_relic/transaction_analysis'
88
90
  require 'new_relic/transaction_sample'
89
91
  require 'new_relic/noticed_error'
@@ -95,7 +97,6 @@ module NewRelic
95
97
  require 'new_relic/agent/method_tracer'
96
98
  require 'new_relic/agent/worker_loop'
97
99
  require 'new_relic/agent/stats_engine'
98
- require 'new_relic/agent/collection_helper'
99
100
  require 'new_relic/agent/transaction_sampler'
100
101
  require 'new_relic/agent/error_collector'
101
102
  require 'new_relic/agent/busy_calculator'
@@ -123,11 +124,11 @@ module NewRelic
123
124
 
124
125
  # Used to blow out of a periodic task without logging a an error, such as for routine
125
126
  # failures.
126
- class IgnoreSilentlyException < StandardError; end
127
+ class ServerConnectionException < StandardError; end
127
128
 
128
129
  # Used for when a transaction trace or error report has too much
129
130
  # data, so we reset the queue to clear the extra-large item
130
- class PostTooBigException < IgnoreSilentlyException; end
131
+ class PostTooBigException < ServerConnectionException; end
131
132
 
132
133
  # Reserved for future use. Meant to represent a problem on the server side.
133
134
  class ServerError < StandardError; end
@@ -24,11 +24,9 @@ module NewRelic
24
24
  attr_reader :stats_engine
25
25
  attr_reader :transaction_sampler
26
26
  attr_reader :error_collector
27
- attr_reader :task_loop
28
27
  attr_reader :record_sql
29
28
  attr_reader :histogram
30
29
  attr_reader :metric_ids
31
- attr_reader :should_send_errors
32
30
 
33
31
  # Should only be called by NewRelic::Control
34
32
  def self.instance
@@ -39,26 +37,30 @@ module NewRelic
39
37
  raise "This method no longer supported. Instead use the class method NewRelic::Agent.manual_start"
40
38
  end
41
39
 
42
- # this method makes sure that the agent is running. it's important
43
- # for passenger where processes are forked and the agent is
44
- # dormant
40
+ # This method attempts to detect when we're in a forked process and tries
41
+ # to re-establish a new agent run. It's important
42
+ # for passenger/unicorn/etc where processes are forked and the worker
43
+ # loop thread is no longer alive.
45
44
  #
46
45
  def ensure_worker_thread_started
47
- return unless control.agent_enabled? && control.monitor_mode? && !@invalid_license
48
- if !running?
49
- # We got some reports of threading errors in Unicorn with this.
50
- log.debug "Detected that the worker loop is not running. Restarting." rescue nil
51
- # Assume we've been forked, clear out stats that are left over from parent process
52
- reset_stats
53
- launch_worker_thread
54
- @stats_engine.spawn_sampler_thread
55
- end
56
- end
57
-
58
- # True if the worker thread has been started. Doesn't necessarily
59
- # mean we are connected
60
- def running?
61
- control.agent_enabled? && control.monitor_mode? && @task_loop && @task_loop.pid == $$
46
+ return if !control.agent_enabled? || @invalid_license
47
+
48
+ # @connected gets false after we fail to connect or have an error
49
+ # connecting. @connected has nil if we haven't finished trying to connect.
50
+ # or we didn't attempt a connection because this is the master process
51
+ return unless @worker_thread && !@worker_thread.alive? && @connected != false
52
+
53
+ # This ensures that we don't enter this block again
54
+ @worker_thread = nil
55
+
56
+ # We got some reports of threading errors in Unicorn with this.
57
+ log.debug "Detected that the worker thread is not running in #$$. Restarting." rescue nil
58
+ # Assume we've been forked if there's a worker_loop already created.
59
+ # Clear out stats that are left over from parent process when we know the parent process
60
+ # did not try to establish a connection
61
+ reset_stats if @connected.nil?
62
+ start_new_run
63
+ @stats_engine.spawn_sampler_thread
62
64
  end
63
65
 
64
66
  # True if we have initialized and completed 'start'
@@ -162,7 +164,8 @@ module NewRelic
162
164
  @started = true
163
165
 
164
166
  sampler_config = control.fetch('transaction_tracer', {})
165
- @use_transaction_sampler = sampler_config.fetch('enabled', true)
167
+ @should_send_samples = sampler_config.fetch('enabled', true)
168
+ log.info "Transaction tracing not enabled." if not @should_send_samples
166
169
 
167
170
  @record_sql = sampler_config.fetch('record_sql', :obfuscated).to_sym
168
171
 
@@ -178,11 +181,6 @@ module NewRelic
178
181
  end
179
182
  @slowest_transaction_threshold = @slowest_transaction_threshold.to_f
180
183
 
181
- if @use_transaction_sampler
182
- log.info "Transaction tracing threshold is #{@slowest_transaction_threshold} seconds."
183
- else
184
- log.info "Transaction tracing not enabled."
185
- end
186
184
  @explain_threshold = sampler_config.fetch('explain_threshold', 0.5).to_f
187
185
  @explain_enabled = sampler_config.fetch('explain_enabled', true)
188
186
  @random_sample = sampler_config.fetch('random_sample', false)
@@ -198,7 +196,7 @@ module NewRelic
198
196
  @invalid_license = true
199
197
  control.log! "Invalid license key: #{control.license_key}", :error
200
198
  else
201
- launch_worker_thread
199
+ start_new_run
202
200
  # When the VM shuts down, attempt to send a message to the
203
201
  # server that this agent run is stopping, assuming it has
204
202
  # successfully connected
@@ -207,7 +205,7 @@ module NewRelic
207
205
  at_exit { shutdown } unless [:sinatra, :unicorn].include? NewRelic::Control.instance.dispatcher
208
206
  end
209
207
  end
210
- control.log! "New Relic RPM Agent #{NewRelic::VERSION::STRING} Initialized: pid = #{$$}"
208
+ control.log! "New Relic RPM Agent #{NewRelic::VERSION::STRING} Initialized: pid = #$$"
211
209
  control.log! "Agent Log found in #{NewRelic::Control.instance.log_file}" if NewRelic::Control.instance.log_file
212
210
  end
213
211
 
@@ -216,71 +214,59 @@ module NewRelic
216
214
  @collector ||= control.server
217
215
  end
218
216
 
219
- # Connect to the server, and run the worker loop forever.
220
- # Will not return.
221
- def run_task_loop
222
- # determine the reporting period (server based)
223
- # note if the agent attempts to report more frequently than
224
- # the specified report data, then it will be ignored.
225
-
226
- control.log! "Reporting performance data every #{@report_period} seconds."
227
- @task_loop.add_task(@report_period, "Timeslice Data Send") do
228
- harvest_and_send_timeslice_data
229
- end
230
-
231
- if @should_send_samples && @use_transaction_sampler
232
- @task_loop.add_task(@report_period, "Transaction Sampler Send") do
233
- harvest_and_send_slowest_sample
234
- end
235
- elsif !control.developer_mode?
236
- # We still need the sampler for dev mode.
237
- @transaction_sampler.disable
238
- end
239
-
240
- if @should_send_errors && @error_collector.enabled
241
- @task_loop.add_task(@report_period, "Error Send") do
242
- harvest_and_send_errors
243
- end
244
- end
245
- log.debug "Running worker loop"
246
- @task_loop.run
247
- rescue StandardError
248
- log.debug "Error in worker loop: #{$!}"
249
- @connected = false
250
- raise
251
- end
252
-
253
- def launch_worker_thread
254
- if (control.dispatcher == :passenger && $0 =~ /ApplicationSpawner/)
255
- log.debug "Process is passenger spawner - don't connect to RPM service"
256
- return
257
- end
258
-
259
- @task_loop = WorkerLoop.new(log)
260
-
217
+ # Try to launch the worker thread and connect to the server
218
+ def start_new_run
219
+ @task_loop = WorkerLoop.new
261
220
  log.debug "Creating RPM worker thread."
262
221
  @worker_thread = Thread.new do
263
222
  begin
264
223
  NewRelic::Agent.disable_all_tracing do
265
- connect
266
- run_task_loop if @connected
224
+ # We try to connect. If this returns false that means
225
+ # the server rejected us for a licensing reason and we should
226
+ # just exit the thread. If it returns nil
227
+ # that means it didn't try to connect because we're in the master
228
+ @connected = connect
229
+ if @connected
230
+ # disable transaction sampling if disabled by the server and we're not in dev mode
231
+ if !control.developer_mode? && !@should_send_samples
232
+ @transaction_sampler.disable
233
+ end
234
+ control.log! "Reporting performance data every #{@report_period} seconds."
235
+ log.debug "Running worker loop"
236
+ # note if the agent attempts to report more frequently than allowed by the server
237
+ # the server will start dropping data.
238
+ @task_loop.run(@report_period) do
239
+ harvest_and_send_timeslice_data
240
+ harvest_and_send_slowest_sample if @should_send_samples
241
+ harvest_and_send_errors if error_collector.enabled
242
+ end
243
+ @connected = false
244
+ end
267
245
  end
268
246
  rescue NewRelic::Agent::ForceRestartException => e
269
247
  log.info e.message
270
248
  # disconnect and start over.
271
249
  # clear the stats engine
272
250
  reset_stats
273
- @connected = false
251
+ @connected = nil
274
252
  # Wait a short time before trying to reconnect
275
253
  sleep 30
276
254
  retry
277
- rescue IgnoreSilentlyException
255
+ rescue ForceDisconnectException => e
256
+ # when a disconnect is requested, stop the current thread, which
257
+ # is the worker thread that gathers data and talks to the
258
+ # server.
259
+ log.error "RPM forced this agent to disconnect (#{e.message})"
260
+ @connected = false
261
+ rescue ServerConnectionException => e
278
262
  control.log! "Unable to establish connection with the server. Run with log level set to debug for more information."
279
- rescue Exception => e
263
+ log.debug("#{e.class.name}: #{e.message}\n#{e.backtrace.first}")
280
264
  @connected = false
265
+ rescue Exception => e
281
266
  log.error "Terminating worker loop: #{e.class.name}: #{e}\n #{e.backtrace.join("\n ")}"
282
- end
283
- end
267
+ @connected = false
268
+ end # begin
269
+ end # thread new
284
270
  @worker_thread['newrelic_label'] = 'Worker Loop'
285
271
  end
286
272
 
@@ -313,6 +299,10 @@ module NewRelic
313
299
  # connection with the server and we should not retry, such as if
314
300
  # there's a bad license key.
315
301
  def connect
302
+ if $0 =~ /ApplicationSpawner|master/
303
+ log.debug "Process is master spawner (#$0) -- don't connect to RPM service"
304
+ return nil
305
+ end
316
306
  # wait a few seconds for the web server to boot, necessary in development
317
307
  connect_retry_period = 5
318
308
  connect_attempts = 0
@@ -320,6 +310,7 @@ module NewRelic
320
310
  begin
321
311
  sleep connect_retry_period.to_i
322
312
  environment = control['send_environment_info'] != false ? control.local_env.snapshot : []
313
+ log.debug "Connecting with validation seed/token: #{control.validate_seed}/#{control.validate_token}" if control.validate_seed
323
314
  @agent_id ||= invoke_remote :start, @local_host, {
324
315
  :pid => $$,
325
316
  :launch_time => @launch_time.to_f,
@@ -340,19 +331,20 @@ module NewRelic
340
331
 
341
332
  # Ask the server for permission to send transaction samples.
342
333
  # determined by subscription license.
343
- @should_send_samples = invoke_remote :should_collect_samples, @agent_id
334
+ @should_send_samples &&= invoke_remote :should_collect_samples, @agent_id
344
335
 
345
336
  if @should_send_samples
346
337
  sampling_rate = invoke_remote :sampling_rate, @agent_id if @random_sample
347
338
  @transaction_sampler.sampling_rate = sampling_rate
348
339
  log.info "Transaction sample rate: #{@transaction_sampler.sampling_rate}" if sampling_rate
340
+ log.info "Transaction tracing threshold is #{@slowest_transaction_threshold} seconds."
349
341
  end
350
342
 
351
343
  # Ask for permission to collect error data
352
- @should_send_errors = invoke_remote :should_collect_errors, @agent_id
344
+ error_collector.enabled &&= invoke_remote(:should_collect_errors, @agent_id)
353
345
 
354
- log.info "Transaction traces will be sent to the RPM service" if @use_transaction_sampler && @should_send_samples
355
- log.info "Errors will be sent to the RPM service" if @error_collector.enabled && @should_send_errors
346
+ log.info "Transaction traces will be sent to the RPM service." if @should_send_samples
347
+ log.info "Errors will be sent to the RPM service." if error_collector.enabled
356
348
 
357
349
  @connected = true
358
350
 
@@ -364,7 +356,7 @@ module NewRelic
364
356
 
365
357
  rescue Timeout::Error, StandardError => e
366
358
  log.info "Unable to establish connection with New Relic RPM Service at #{control.server}"
367
- unless e.instance_of? IgnoreSilentlyException
359
+ unless e.instance_of? ServerConnectionException
368
360
  log.error e.message
369
361
  log.debug e.backtrace.join("\n")
370
362
  end
@@ -376,7 +368,7 @@ module NewRelic
376
368
  when 3..5 then
377
369
  connect_retry_period, period_msg = 60 * 2, "2 minutes"
378
370
  else
379
- connect_retry_period, period_msg = 10*60, "10 minutes"
371
+ connect_retry_period, period_msg = 10 * 60, "10 minutes"
380
372
  end
381
373
  log.info "Will re-attempt in #{period_msg}"
382
374
  retry
@@ -427,6 +419,7 @@ module NewRelic
427
419
  end if metric_ids
428
420
 
429
421
  log.debug "#{now}: sent #{@unsent_timeslice_data.length} timeslices (#{@agent_id}) in #{Time.now - now} seconds"
422
+ puts "#{now}: sent #{@unsent_timeslice_data.length} timeslices (#{@agent_id}) in #{Time.now - now} seconds"
430
423
 
431
424
  # if we successfully invoked this web service, then clear the unsent message cache.
432
425
  @unsent_timeslice_data = {}
@@ -540,14 +533,12 @@ module NewRelic
540
533
  raise
541
534
  end
542
535
  if response.is_a? Net::HTTPServiceUnavailable
543
- log.debug(response.body || response.message)
544
- raise IgnoreSilentlyException
536
+ raise ServerConnectionException, "Service unavailable: #{response.body || response.message}"
545
537
  elsif response.is_a? Net::HTTPGatewayTimeOut
546
538
  log.debug("Timed out getting response: #{response.message}")
547
539
  raise Timeout::Error, response.message
548
540
  elsif !(response.is_a? Net::HTTPSuccess)
549
- log.debug "Unexpected response from server: #{response.code}: #{response.message}"
550
- raise IgnoreSilentlyException
541
+ raise ServerConnectionException, "Unexpected response from server: #{response.code}: #{response.message}"
551
542
  end
552
543
  response
553
544
  end
@@ -587,18 +578,9 @@ module NewRelic
587
578
  rescue ForceRestartException => e
588
579
  log.info e.message
589
580
  raise
590
- rescue ForceDisconnectException => e
591
- log.error "RPM forced this agent to disconnect (#{e.message})\n" \
592
- "Restart this process to resume monitoring via rpm.newrelic.com."
593
- # when a disconnect is requested, stop the current thread, which
594
- # is the worker thread that gathers data and talks to the
595
- # server.
596
- @connected = false
597
- Thread.exit
598
581
  rescue SystemCallError, SocketError => e
599
582
  # These include Errno connection errors
600
- log.debug "Recoverable error connecting to the server: #{e}"
601
- raise IgnoreSilentlyException
583
+ raise ServerConnectionException, "Recoverable error connecting to the server: #{e}"
602
584
  end
603
585
 
604
586
  def graceful_disconnect
@@ -607,11 +589,9 @@ module NewRelic
607
589
  log.debug "Sending graceful shutdown message to #{control.server}"
608
590
 
609
591
  @request_timeout = 5
610
-
592
+ log.debug "Flushing unsent metric data to server"
593
+ @task_loop.run_task
611
594
  log.debug "Sending RPM service agent run shutdown message"
612
- harvest_and_send_timeslice_data
613
- # harvest_and_send_slowest_sample
614
- harvest_and_send_errors
615
595
  invoke_remote :shutdown, @agent_id, Time.now.to_f
616
596
 
617
597
  log.debug "Graceful shutdown complete"
@@ -2,7 +2,7 @@
2
2
  module NewRelic
3
3
  module Agent
4
4
  class ErrorCollector
5
- include CollectionHelper
5
+ include NewRelic::CollectionHelper
6
6
 
7
7
  # Defined the methods that need to be stubbed out when the
8
8
  # agent is disabled
@@ -61,7 +61,6 @@ module NewRelic
61
61
  end
62
62
 
63
63
  NewRelic::Agent.get_stats("Errors/all").increment_count
64
- return unless NewRelic::Agent.instance.should_send_errors
65
64
 
66
65
  data = {}
67
66
  data[:request_uri] = options.delete(:uri) || ''
@@ -1,8 +1,8 @@
1
1
  if defined? Authlogic::Session::Base
2
2
  Authlogic::Session::Base.class_eval do
3
- # add_method_tracer :record, 'Authlogic/record'
3
+ # add_method_tracer :record, 'Custom/Authlogic/record'
4
4
  class << self
5
- add_method_tracer :find, 'Authlogic/find'
5
+ add_method_tracer :find, 'Custom/Authlogic/find'
6
6
  end
7
7
  end
8
8
  end
@@ -18,8 +18,8 @@ Merb::Controller.class_eval do
18
18
  protected
19
19
  # determine the path that is used in the metric name for
20
20
  # the called controller action
21
- def newrelic_metric_path(action)
22
- "#{controller_name}/#{action}"
21
+ def newrelic_metric_path
22
+ "#{controller_name}/#{action_name}"
23
23
  end
24
24
  alias_method :perform_action_without_newrelic_trace, :_dispatch
25
25
  alias_method :_dispatch, :perform_action_with_newrelic_trace
@@ -0,0 +1,45 @@
1
+ module NewRelic
2
+ module Agent
3
+ module Instrumentation
4
+ module Rails3
5
+ module ActionController
6
+ def self.newrelic_write_attr(attr_name, value) # :nodoc:
7
+ write_inheritable_attribute(attr_name, value)
8
+ end
9
+
10
+ def self.newrelic_read_attr(attr_name) # :nodoc:
11
+ read_inheritable_attribute(attr_name)
12
+ end
13
+
14
+ # determine the path that is used in the metric name for
15
+ # the called controller action
16
+ def newrelic_metric_path(action_name_override = nil)
17
+ action_part = action_name_override || action_name
18
+ if action_name_override || self.class.action_methods.include?(action_part)
19
+ "#{self.class.controller_path}/#{action_part}"
20
+ else
21
+ "#{self.class.controller_path}/(other)"
22
+ end
23
+ end
24
+
25
+ def process_action(*args)
26
+
27
+ perform_action_with_newrelic_trace(:category => :controller, :name => self.action_name, :params => request.filtered_parameters, :class_name => self.class.name) do
28
+ super
29
+ end
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ if defined?(ActionController) && defined?(ActionController::Base)
39
+ puts "ApplicationController is defined"
40
+ class ActionController::Base
41
+ include NewRelic::Agent::Instrumentation::ControllerInstrumentation
42
+ include NewRelic::Agent::Instrumentation::Rails3::ActionController
43
+ end
44
+ end
45
+