newrelic_rpm 2.13.0.beta5 → 2.13.1

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 (86) hide show
  1. data/CHANGELOG +4 -0
  2. data/lib/new_relic/agent.rb +50 -50
  3. data/lib/new_relic/agent/agent.rb +24 -19
  4. data/lib/new_relic/agent/busy_calculator.rb +22 -22
  5. data/lib/new_relic/agent/chained_call.rb +3 -3
  6. data/lib/new_relic/agent/error_collector.rb +19 -19
  7. data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +11 -11
  8. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +2 -2
  9. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +43 -43
  10. data/lib/new_relic/agent/instrumentation/data_mapper.rb +6 -6
  11. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +2 -2
  12. data/lib/new_relic/agent/instrumentation/memcache.rb +8 -8
  13. data/lib/new_relic/agent/instrumentation/merb/controller.rb +4 -4
  14. data/lib/new_relic/agent/instrumentation/metric_frame.rb +307 -303
  15. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +8 -8
  16. data/lib/new_relic/agent/instrumentation/rack.rb +2 -2
  17. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +10 -10
  18. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +3 -3
  19. data/lib/new_relic/agent/instrumentation/rails/errors.rb +5 -5
  20. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +5 -5
  21. data/lib/new_relic/agent/instrumentation/sinatra.rb +5 -5
  22. data/lib/new_relic/agent/instrumentation/sunspot.rb +1 -1
  23. data/lib/new_relic/agent/method_tracer.rb +55 -55
  24. data/lib/new_relic/agent/sampler.rb +42 -38
  25. data/lib/new_relic/agent/samplers/cpu_sampler.rb +4 -4
  26. data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +7 -7
  27. data/lib/new_relic/agent/samplers/memory_sampler.rb +11 -11
  28. data/lib/new_relic/agent/samplers/object_sampler.rb +1 -1
  29. data/lib/new_relic/agent/shim_agent.rb +20 -16
  30. data/lib/new_relic/agent/stats_engine.rb +3 -3
  31. data/lib/new_relic/agent/stats_engine/metric_stats.rb +28 -28
  32. data/lib/new_relic/agent/stats_engine/samplers.rb +16 -16
  33. data/lib/new_relic/agent/stats_engine/transactions.rb +25 -25
  34. data/lib/new_relic/agent/transaction_sampler.rb +68 -69
  35. data/lib/new_relic/agent/worker_loop.rb +13 -13
  36. data/lib/new_relic/collection_helper.rb +6 -6
  37. data/lib/new_relic/command.rb +14 -14
  38. data/lib/new_relic/commands/deployments.rb +19 -19
  39. data/lib/new_relic/commands/install.rb +25 -15
  40. data/lib/new_relic/control.rb +25 -25
  41. data/lib/new_relic/control/configuration.rb +17 -17
  42. data/lib/new_relic/control/frameworks/external.rb +3 -3
  43. data/lib/new_relic/control/frameworks/merb.rb +6 -6
  44. data/lib/new_relic/control/frameworks/rails.rb +17 -17
  45. data/lib/new_relic/control/frameworks/rails3.rb +11 -27
  46. data/lib/new_relic/control/frameworks/ruby.rb +6 -6
  47. data/lib/new_relic/control/frameworks/sinatra.rb +4 -4
  48. data/lib/new_relic/control/instrumentation.rb +8 -8
  49. data/lib/new_relic/control/logging_methods.rb +13 -13
  50. data/lib/new_relic/control/profiling.rb +2 -2
  51. data/lib/new_relic/control/server_methods.rb +17 -17
  52. data/lib/new_relic/delayed_job_injection.rb +1 -1
  53. data/lib/new_relic/histogram.rb +73 -71
  54. data/lib/new_relic/local_environment.rb +45 -45
  55. data/lib/new_relic/merbtasks.rb +1 -1
  56. data/lib/new_relic/metric_data.rb +5 -5
  57. data/lib/new_relic/metric_parser.rb +22 -22
  58. data/lib/new_relic/metric_parser/action_mailer.rb +4 -4
  59. data/lib/new_relic/metric_parser/active_merchant.rb +8 -8
  60. data/lib/new_relic/metric_parser/active_record.rb +2 -2
  61. data/lib/new_relic/metric_parser/apdex.rb +86 -51
  62. data/lib/new_relic/metric_parser/controller.rb +10 -10
  63. data/lib/new_relic/metric_parser/controller_cpu.rb +5 -5
  64. data/lib/new_relic/metric_parser/errors.rb +1 -1
  65. data/lib/new_relic/metric_parser/external.rb +3 -3
  66. data/lib/new_relic/metric_parser/mem_cache.rb +2 -2
  67. data/lib/new_relic/metric_parser/other_transaction.rb +7 -7
  68. data/lib/new_relic/metric_parser/view.rb +5 -5
  69. data/lib/new_relic/metric_parser/web_frontend.rb +1 -1
  70. data/lib/new_relic/metric_parser/web_service.rb +1 -1
  71. data/lib/new_relic/metric_spec.rb +13 -13
  72. data/lib/new_relic/noticed_error.rb +4 -4
  73. data/lib/new_relic/rack/developer_mode.rb +33 -33
  74. data/lib/new_relic/rack/metric_app.rb +2 -2
  75. data/lib/new_relic/recipes.rb +9 -9
  76. data/lib/new_relic/stats.rb +57 -57
  77. data/lib/new_relic/timer_lib.rb +2 -2
  78. data/lib/new_relic/transaction_analysis.rb +19 -19
  79. data/lib/new_relic/transaction_sample.rb +101 -101
  80. data/lib/new_relic/url_rule.rb +3 -3
  81. data/lib/new_relic/version.rb +10 -10
  82. data/lib/newrelic_rpm.rb +6 -4
  83. data/lib/tasks/all.rb +1 -1
  84. data/newrelic_rpm.gemspec +3 -3
  85. data/test/new_relic/rack/episodes_test.rb +1 -0
  86. metadata +24 -42
@@ -1,22 +1,22 @@
1
1
  if defined?(PhusionPassenger)
2
2
  NewRelic::Agent.logger.debug "Installing Passenger event hooks."
3
-
4
- PhusionPassenger.on_event(:stopping_worker_process) do
3
+
4
+ PhusionPassenger.on_event(:stopping_worker_process) do
5
5
  NewRelic::Agent.logger.debug "Passenger stopping this process, shutdown the agent."
6
6
  NewRelic::Agent.instance.shutdown
7
7
  end
8
-
8
+
9
9
  PhusionPassenger.on_event(:starting_worker_process) do |forked|
10
10
  # We want to reset the stats from the stats engine in case any carried
11
11
  # over into the spawned process. Don't clear them in case any were
12
12
  # cached. We do this even in conservative spawning.
13
13
  NewRelic::Agent.after_fork(:force_reconnect => true)
14
14
  end
15
-
16
- elsif (defined?(::Passenger) && defined?(::Passenger::AbstractServer)) || defined?(::IN_PHUSION_PASSENGER)
15
+
16
+ elsif (defined?(::Passenger) && defined?(::Passenger::AbstractServer)) || defined?(::IN_PHUSION_PASSENGER)
17
17
  # We're on an older version of passenger
18
18
  NewRelic::Agent.logger.warn "An older version of Phusion Passenger has been detected. We recommend using at least release 2.1.1."
19
-
19
+
20
20
  NewRelic::Agent::Instrumentation::MetricFrame.check_server_connection = true
21
-
22
- end
21
+
22
+ end
@@ -47,10 +47,10 @@ module NewRelic
47
47
  # end
48
48
  # end
49
49
  # end
50
- #
50
+ #
51
51
  # == Overriding the metric name
52
52
  #
53
- # By default the middleware is identified only by its class, but if you want to
53
+ # By default the middleware is identified only by its class, but if you want to
54
54
  # be more specific and pass in name, then omit including the Rack instrumentation
55
55
  # and instead follow this example:
56
56
  #
@@ -1,12 +1,12 @@
1
1
 
2
2
  if defined? ActionController
3
-
3
+
4
4
  case Rails::VERSION::STRING
5
5
 
6
6
  when /^(1\.|2\.0)/ # Rails 1.* - 2.0
7
7
  ActionController::Base.class_eval do
8
8
  add_method_tracer :render, 'View/#{newrelic_metric_path}/Rendering'
9
- end
9
+ end
10
10
 
11
11
  when /^2\.1\./ # Rails 2.1
12
12
  ActionView::PartialTemplate.class_eval do
@@ -25,24 +25,24 @@ if defined? ActionController
25
25
  add_method_tracer :render, 'View/#{path[%r{^(/.*/)?(.*)$},2]}/Rendering'
26
26
  end
27
27
  end unless NewRelic::Control.instance['disable_view_instrumentation']
28
-
28
+
29
29
  ActionController::Base.class_eval do
30
30
  include NewRelic::Agent::Instrumentation::ControllerInstrumentation
31
-
32
- # Compare with #alias_method_chain, which is not available in
31
+
32
+ # Compare with #alias_method_chain, which is not available in
33
33
  # Rails 1.1:
34
34
  alias_method :perform_action_without_newrelic_trace, :perform_action
35
35
  alias_method :perform_action, :perform_action_with_newrelic_trace
36
36
  private :perform_action
37
-
37
+
38
38
  def self.newrelic_write_attr(attr_name, value) # :nodoc:
39
39
  write_inheritable_attribute(attr_name, value)
40
40
  end
41
-
41
+
42
42
  def self.newrelic_read_attr(attr_name) # :nodoc:
43
43
  read_inheritable_attribute(attr_name)
44
44
  end
45
-
45
+
46
46
  # determine the path that is used in the metric name for
47
47
  # the called controller action
48
48
  def newrelic_metric_path(action_name_override = nil)
@@ -53,7 +53,7 @@ if defined? ActionController
53
53
  "#{self.class.controller_path}/(other)"
54
54
  end
55
55
  end
56
- end
56
+ end
57
57
  else
58
58
  NewRelic::Agent.instance.log.debug "WARNING: ActionController instrumentation not added"
59
- end
59
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Note Action Web Service is removed from default package in rails 2.0
4
4
  if defined? ActionWebService
5
-
5
+
6
6
  # instrumentation for Web Service martialing - XML RPC
7
7
  ActionWebService::Protocol::XmlRpc::XmlRpcProtocol.class_eval do
8
8
  add_method_tracer :decode_request, "WebService/Xml Rpc/XML Decode"
@@ -10,7 +10,7 @@ if defined? ActionWebService
10
10
  add_method_tracer :decode_response, "WebService/Xml Rpc/XML Decode"
11
11
  add_method_tracer :encode_response, "WebService/Xml Rpc/XML Encode"
12
12
  end
13
-
13
+
14
14
  # instrumentation for Web Service martialing - Soap
15
15
  ActionWebService::Protocol::Soap::SoapProtocol.class_eval do
16
16
  add_method_tracer :decode_request, "WebService/Soap/XML Decode"
@@ -18,7 +18,7 @@ if defined? ActionWebService
18
18
  add_method_tracer :decode_response, "WebService/Soap/XML Decode"
19
19
  add_method_tracer :encode_response, "WebService/Soap/XML Encode"
20
20
  end
21
-
21
+
22
22
  ActionController::Base.class_eval do
23
23
  if method_defined? :perform_invocation
24
24
  add_method_tracer :perform_invocation, 'WebService/#{controller_name}/#{args.first}'
@@ -1,6 +1,6 @@
1
1
 
2
2
  ActionController::Base.class_eval do
3
-
3
+
4
4
  # Make a note of an exception associated with the currently executing
5
5
  # controller action. Note that this used to be available on Object
6
6
  # but we replaced that global method with NewRelic::Agent#notice_error.
@@ -8,13 +8,13 @@ ActionController::Base.class_eval do
8
8
  def newrelic_notice_error(exception, custom_params = {})
9
9
  NewRelic::Agent::Instrumentation::MetricFrame.notice_error exception, :custom_params => custom_params, :request => request
10
10
  end
11
-
11
+
12
12
  def rescue_action_with_newrelic_trace(exception)
13
13
  rescue_action_without_newrelic_trace exception
14
- NewRelic::Agent::Instrumentation::MetricFrame.notice_error exception, :request => request
14
+ NewRelic::Agent::Instrumentation::MetricFrame.notice_error exception, :request => request
15
15
  end
16
-
17
- # Compare with #alias_method_chain, which is not available in
16
+
17
+ # Compare with #alias_method_chain, which is not available in
18
18
  # Rails 1.1:
19
19
  alias_method :rescue_action_without_newrelic_trace, :rescue_action
20
20
  alias_method :rescue_action, :rescue_action_with_newrelic_trace
@@ -6,11 +6,11 @@ module NewRelic
6
6
  def self.newrelic_write_attr(attr_name, value) # :nodoc:
7
7
  write_inheritable_attribute(attr_name, value)
8
8
  end
9
-
9
+
10
10
  def self.newrelic_read_attr(attr_name) # :nodoc:
11
11
  read_inheritable_attribute(attr_name)
12
12
  end
13
-
13
+
14
14
  # determine the path that is used in the metric name for
15
15
  # the called controller action
16
16
  def newrelic_metric_path(action_name_override = nil)
@@ -23,12 +23,12 @@ module NewRelic
23
23
  end
24
24
 
25
25
  def process_action(*args)
26
-
26
+
27
27
  perform_action_with_newrelic_trace(:category => :controller, :name => self.action_name, :params => request.filtered_parameters, :class_name => self.class.name) do
28
28
  super
29
29
  end
30
30
  end
31
-
31
+
32
32
  end
33
33
  end
34
34
  end
@@ -36,7 +36,7 @@ module NewRelic
36
36
  end
37
37
 
38
38
  if defined?(ActionController) && defined?(ActionController::Base)
39
- puts "ApplicationController is defined"
39
+ puts "ApplicationController is defined"
40
40
  class ActionController::Base
41
41
  include NewRelic::Agent::Instrumentation::ControllerInstrumentation
42
42
  include NewRelic::Agent::Instrumentation::Rails3::ActionController
@@ -3,7 +3,7 @@ if defined?(Sinatra::Base)
3
3
  module NewRelic
4
4
  module Agent
5
5
  module Instrumentation
6
- # NewRelic instrumentation for Sinatra applications. Sinatra actions will
6
+ # NewRelic instrumentation for Sinatra applications. Sinatra actions will
7
7
  # appear in the UI similar to controller actions, and have breakdown charts
8
8
  # and transaction traces.
9
9
  #
@@ -11,9 +11,9 @@ if defined?(Sinatra::Base)
11
11
  # to match them. HTTP operations are not distinguished. Multiple matches
12
12
  # will all be tracked as separate actions.
13
13
  module Sinatra
14
-
14
+
15
15
  include NewRelic::Agent::Instrumentation::ControllerInstrumentation
16
-
16
+
17
17
  def route_eval_with_newrelic(&block_arg)
18
18
  path = unescape(@request.path_info)
19
19
  name = path
@@ -33,13 +33,13 @@ if defined?(Sinatra::Base)
33
33
  end
34
34
  end
35
35
  end
36
-
36
+
37
37
  ::Sinatra::Base.class_eval do
38
38
  include NewRelic::Agent::Instrumentation::Sinatra
39
39
  alias route_eval_without_newrelic route_eval
40
40
  alias route_eval route_eval_with_newrelic
41
41
  end
42
-
42
+
43
43
  end
44
44
  end
45
45
  end
@@ -5,7 +5,7 @@ if defined?(::Sunspot)
5
5
  add_method_tracer method, 'SolrClient/Sunspot/index'
6
6
  end
7
7
  add_method_tracer :commit, 'SolrClient/Sunspot/commit'
8
-
8
+
9
9
  %w[search more_like_this].each do |method|
10
10
  add_method_tracer method, 'SolrClient/Sunspot/query'
11
11
  end
@@ -34,7 +34,7 @@ module Agent
34
34
  # end
35
35
 
36
36
  module MethodTracer
37
-
37
+
38
38
  def self.included clazz #:nodoc:
39
39
  clazz.extend ClassMethods
40
40
  clazz.send :include, InstanceMethods
@@ -48,21 +48,21 @@ module Agent
48
48
  module InstanceMethods
49
49
  # Deprecated: original method preserved for API backward compatibility.
50
50
  # Use either #trace_execution_scoped or #trace_execution_unscoped
51
- def trace_method_execution(metric_names, push_scope, produce_metric, deduct_call_time_from_parent, &block) #:nodoc:
51
+ def trace_method_execution(metric_names, push_scope, produce_metric, deduct_call_time_from_parent, &block) #:nodoc:
52
52
  if push_scope
53
- trace_execution_scoped(metric_names, :metric => produce_metric,
53
+ trace_execution_scoped(metric_names, :metric => produce_metric,
54
54
  :deduct_call_time_from_parent => deduct_call_time_from_parent, &block)
55
55
  else
56
56
  trace_execution_unscoped(metric_names, &block)
57
57
  end
58
58
  end
59
-
60
- # Trace a given block with stats assigned to the given metric_name. It does not
59
+
60
+ # Trace a given block with stats assigned to the given metric_name. It does not
61
61
  # provide scoped measurements, meaning whatever is being traced will not 'blame the
62
- # Controller'--that is to say appear in the breakdown chart.
62
+ # Controller'--that is to say appear in the breakdown chart.
63
63
  # This is code is inlined in #add_method_tracer.
64
64
  # * <tt>metric_names</tt> is a single name or an array of names of metrics
65
- # * <tt>:force => true</tt> will force the metric to be captured even when
65
+ # * <tt>:force => true</tt> will force the metric to be captured even when
66
66
  # tracing is disabled with NewRelic::Agent#disable_all_tracing
67
67
  #
68
68
  def trace_execution_unscoped(metric_names, options={})
@@ -80,20 +80,20 @@ module Agent
80
80
  stats.each { |stat| stat.trace_call(duration) }
81
81
  end
82
82
  end
83
-
83
+
84
84
  EMPTY_ARRAY = [].freeze
85
-
86
- # Deprecated. Use #trace_execution_scoped, a version with an options hash.
85
+
86
+ # Deprecated. Use #trace_execution_scoped, a version with an options hash.
87
87
  def trace_method_execution_with_scope(metric_names, produce_metric, deduct_call_time_from_parent, scoped_metric_only=false, &block) #:nodoc:
88
- trace_execution_scoped(metric_names,
89
- :metric => produce_metric,
90
- :deduct_call_time_from_parent => deduct_call_time_from_parent,
88
+ trace_execution_scoped(metric_names,
89
+ :metric => produce_metric,
90
+ :deduct_call_time_from_parent => deduct_call_time_from_parent,
91
91
  :scoped_metric_only => scoped_metric_only, &block)
92
92
  end
93
-
93
+
94
94
  alias trace_method_execution_no_scope trace_execution_unscoped #:nodoc:
95
-
96
- # Trace a given block with stats and keep track of the caller.
95
+
96
+ # Trace a given block with stats and keep track of the caller.
97
97
  # See NewRelic::Agent::MethodTracer::ClassMethods#add_method_tracer for a description of the arguments.
98
98
  # +metric_names+ is either a single name or an array of metric names.
99
99
  # If more than one metric is passed, the +produce_metric+ option only applies to the first. The
@@ -102,11 +102,11 @@ module Agent
102
102
  # Generally you pass an array of metric names if you want to record the metric under additional
103
103
  # categories, but generally this *should never ever be done*. Most of the time you can aggregate
104
104
  # on the server.
105
-
105
+
106
106
  def trace_execution_scoped(metric_names, options={})
107
-
107
+
108
108
  return yield unless NewRelic::Agent.is_execution_traced? || options[:force]
109
-
109
+
110
110
  produce_metric = options[:metric] != false
111
111
  deduct_call_time_from_parent = options[:deduct_call_time_from_parent] != false
112
112
  scoped_metric_only = produce_metric && options[:scoped_metric_only]
@@ -116,33 +116,33 @@ module Agent
116
116
  metric_stats = []
117
117
  metric_stats << NewRelic::Agent.instance.stats_engine.get_stats(first_name, true, scoped_metric_only) if produce_metric
118
118
  metric_names[1..-1].each do | name |
119
- metric_stats << NewRelic::Agent.instance.stats_engine.get_stats_no_scope(name)
119
+ metric_stats << NewRelic::Agent.instance.stats_engine.get_stats_no_scope(name)
120
120
  end
121
121
  else
122
- first_name = metric_names
122
+ first_name = metric_names
123
123
  if produce_metric
124
124
  metric_stats = [NewRelic::Agent.instance.stats_engine.get_stats(first_name, true, scoped_metric_only)]
125
125
  else
126
126
  metric_stats = EMPTY_ARRAY
127
127
  end
128
128
  end
129
-
129
+
130
130
  begin
131
131
  # Keep a reference to the scope we are pushing so we can do a sanity check making
132
132
  # sure when we pop we get the one we 'expected'
133
- NewRelic::Agent.instance.push_trace_execution_flag(true) if options[:force]
133
+ NewRelic::Agent.instance.push_trace_execution_flag(true) if options[:force]
134
134
  expected_scope = NewRelic::Agent.instance.stats_engine.push_scope(first_name, t0.to_f, deduct_call_time_from_parent)
135
135
  rescue => e
136
136
  NewRelic::Control.instance.log.error("Caught exception in trace_method_execution header. Metric name = #{first_name}, exception = #{e}")
137
137
  NewRelic::Control.instance.log.error(e.backtrace.join("\n"))
138
138
  end
139
-
139
+
140
140
  begin
141
141
  yield
142
142
  ensure
143
143
  t1 = Time.now
144
144
  duration = (t1 - t0).to_f
145
-
145
+
146
146
  begin
147
147
  NewRelic::Agent.instance.pop_trace_execution_flag if options[:force]
148
148
  if expected_scope
@@ -157,19 +157,19 @@ module Agent
157
157
  end
158
158
  end
159
159
  end
160
-
160
+
161
161
  module ClassMethods
162
162
  # Add a method tracer to the specified method.
163
163
  #
164
164
  # === Common Options
165
165
  #
166
- # * <tt>:push_scope => false</tt> specifies this method tracer should not
166
+ # * <tt>:push_scope => false</tt> specifies this method tracer should not
167
167
  # keep track of the caller; it will not show up in controller breakdown
168
- # pie charts.
168
+ # pie charts.
169
169
  # * <tt>:metric => false</tt> specifies that no metric will be recorded.
170
170
  # Instead the call will show up in transaction traces as well as traces
171
- # shown in Developer Mode.
172
- #
171
+ # shown in Developer Mode.
172
+ #
173
173
  # === Uncommon Options
174
174
  #
175
175
  # * <tt>:scoped_metric_only => true</tt> indicates that the unscoped metric
@@ -181,18 +181,18 @@ module Agent
181
181
  # The effect is similar to <tt>:metric => false</tt> but in addition you
182
182
  # will also see the invocation in breakdown pie charts.
183
183
  # * <tt>:deduct_call_time_from_parent => false</tt> indicates that the method invocation
184
- # time should never be deducted from the time reported as 'exclusive' in the
184
+ # time should never be deducted from the time reported as 'exclusive' in the
185
185
  # caller. You would want to use this if you are tracing a recursive method
186
186
  # or a method that might be called inside another traced method.
187
- # * <tt>:code_header</tt> and <tt>:code_footer</tt> specify ruby code that
187
+ # * <tt>:code_header</tt> and <tt>:code_footer</tt> specify ruby code that
188
188
  # is inserted into the tracer before and after the call.
189
189
  # * <tt>:force = true</tt> will ensure the metric is captured even if called inside
190
190
  # an untraced execution call. (See NewRelic::Agent#disable_all_tracing)
191
191
  #
192
192
  # === Overriding the metric name
193
193
  #
194
- # +metric_name_code+ is a string that is eval'd to get the
195
- # name of the metric associated with the call, so if you want to
194
+ # +metric_name_code+ is a string that is eval'd to get the
195
+ # name of the metric associated with the call, so if you want to
196
196
  # use interpolaion evaluated at call time, then single quote
197
197
  # the value like this:
198
198
  #
@@ -217,22 +217,22 @@ module Agent
217
217
  # for actions:
218
218
  #
219
219
  # add_method_tracer :foo
220
- #
220
+ #
221
221
  # which is equivalent to:
222
222
  #
223
223
  # add_method_tracer :foo, 'Custom/#{self.class.name}/foo', :push_scope => true, :metric => true
224
224
  #
225
225
  # Instrument the class method +foo+ with the metric name 'Custom/People/fetch':
226
- #
226
+ #
227
227
  # class << self
228
228
  # add_method_tracer :foo, 'Custom/People/fetch'
229
229
  # end
230
230
  #
231
-
231
+
232
232
  def add_method_tracer(method_name, metric_name_code=nil, options = {})
233
233
  # for backward compatibility:
234
234
  if !options.is_a?(Hash)
235
- options = {:push_scope => options}
235
+ options = {:push_scope => options}
236
236
  end
237
237
  # in case they omit the metric name code
238
238
  if metric_name_code.is_a?(Hash)
@@ -253,24 +253,24 @@ module Agent
253
253
  options[:code_header] ||= ""
254
254
  options[:code_footer] ||= ""
255
255
  options[:scoped_metric_only] ||= false
256
-
256
+
257
257
  klass = (self === Module) ? "self" : "self.class"
258
258
  # Default to the class where the method is defined.
259
259
  metric_name_code = "Custom/#{self.name}/#{method_name.to_s}" unless metric_name_code
260
-
260
+
261
261
  unless method_defined?(method_name) || private_method_defined?(method_name)
262
262
  NewRelic::Control.instance.log.warn("Did not trace #{self.name}##{method_name} because that method does not exist")
263
263
  return
264
264
  end
265
-
265
+
266
266
  traced_method_name = _traced_method_name(method_name, metric_name_code)
267
267
  if method_defined? traced_method_name
268
268
  NewRelic::Control.instance.log.warn("Attempt to trace a method twice with the same metric: Method = #{method_name}, Metric Name = #{metric_name_code}")
269
269
  return
270
270
  end
271
-
271
+
272
272
  fail "Can't add a tracer where push_scope is false and metric is false" if options[:push_scope] == false && !options[:metric]
273
-
273
+
274
274
  header = ""
275
275
  if !options[:force]
276
276
  header << "return #{_untraced_method_name(method_name, metric_name_code)}(*args, &block) unless NewRelic::Agent.is_execution_traced?\n"
@@ -297,10 +297,10 @@ module Agent
297
297
  code = <<-CODE
298
298
  def #{_traced_method_name(method_name, metric_name_code)}(*args, &block)
299
299
  #{options[:code_header]}
300
- result = #{klass}.trace_execution_scoped("#{metric_name_code}",
300
+ result = #{klass}.trace_execution_scoped("#{metric_name_code}",
301
301
  :metric => #{options[:metric]},
302
- :forced => #{options[:force]},
303
- :deduct_call_time_from_parent => #{options[:deduct_call_time_from_parent]},
302
+ :forced => #{options[:force]},
303
+ :deduct_call_time_from_parent => #{options[:deduct_call_time_from_parent]},
304
304
  :scoped_metric_only => #{options[:scoped_metric_only]}) do
305
305
  #{_untraced_method_name(method_name, metric_name_code)}(*args, &block)
306
306
  end
@@ -310,20 +310,20 @@ module Agent
310
310
  CODE
311
311
  end
312
312
  class_eval code, __FILE__, __LINE__
313
-
313
+
314
314
  alias_method _untraced_method_name(method_name, metric_name_code), method_name
315
315
  alias_method method_name, _traced_method_name(method_name, metric_name_code)
316
-
316
+
317
317
  NewRelic::Control.instance.log.debug("Traced method: class = #{self.name}, method = #{method_name}, "+
318
318
  "metric = '#{metric_name_code}'")
319
319
  end
320
-
320
+
321
321
  # For tests only because tracers must be removed in reverse-order
322
322
  # from when they were added, or else other tracers that were added to the same method
323
323
  # may get removed as well.
324
324
  def remove_method_tracer(method_name, metric_name_code) # :nodoc:
325
325
  return unless NewRelic::Control.instance.agent_enabled?
326
-
326
+
327
327
  if method_defined? "#{_traced_method_name(method_name, metric_name_code)}"
328
328
  alias_method method_name, "#{_untraced_method_name(method_name, metric_name_code)}"
329
329
  undef_method "#{_traced_method_name(method_name, metric_name_code)}"
@@ -332,15 +332,15 @@ module Agent
332
332
  end
333
333
  end
334
334
  private
335
-
335
+
336
336
  def _untraced_method_name(method_name, metric_name)
337
- "#{_sanitize_name(method_name)}_without_trace_#{_sanitize_name(metric_name)}"
337
+ "#{_sanitize_name(method_name)}_without_trace_#{_sanitize_name(metric_name)}"
338
338
  end
339
-
339
+
340
340
  def _traced_method_name(method_name, metric_name)
341
- "#{_sanitize_name(method_name)}_with_trace_#{_sanitize_name(metric_name)}"
341
+ "#{_sanitize_name(method_name)}_with_trace_#{_sanitize_name(metric_name)}"
342
342
  end
343
-
343
+
344
344
  def _sanitize_name(name)
345
345
  name.to_s.tr_s('^a-zA-Z0-9', '_')
346
346
  end