Module: TingYun::Agent::MethodTracer::ClassMethods
- Includes:
- AddMethodTracer
- Defined in:
- lib/ting_yun/agent/method_tracer.rb
Overview
Defines methods used at the class level, for adding instrumentation
Defined Under Namespace
Modules: AddMethodTracer
Instance Method Summary collapse
-
#add_method_tracer(method_name, metric_name_code = nil, options = {}) ⇒ Object
Add a method tracer to the specified method.
Methods included from AddMethodTracer
#_method_exists?, #assemble_code_header, #code_to_eval, #default_metric_name_code, #method_with_push_scope, #method_without_push_scope, #traced_method_exists?
Instance Method Details
#add_method_tracer(method_name, metric_name_code = nil, options = {}) ⇒ Object
Add a method tracer to the specified method.
By default, this will cause invocations of the traced method to be recorded in transaction traces, and in a metric named after the class and method. It will also make the method show up in transaction-level breakdown charts and tables.
Overriding the metric name
metric_name_code
is a string that is eval’d to get the name of the metric associated with the call, so if you want to use interpolation evaluated at call time, then single quote the value like this:
add_method_tracer :foo, 'Custom/#{self.class.name}/foo'
This would name the metric according to the class of the runtime intance, as opposed to the class where foo
is defined.
If not provided, the metric name will be Custom/ClassName/method_name
.
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/ting_yun/agent/method_tracer.rb', line 209 def add_method_tracer(method_name, metric_name_code=nil, = {}) return unless _method_exists?(method_name) metric_name_code ||= default_metric_name_code(method_name) return if traced_method_exists?(method_name, metric_name_code) traced_method = code_to_eval(method_name, metric_name_code, ) visibility = TingYun::Support::Helper.instance_method_visibility self, method_name class_eval traced_method, __FILE__, __LINE__ alias_method _untraced_method_name(method_name, metric_name_code), method_name alias_method method_name, _traced_method_name(method_name, metric_name_code) send visibility, method_name send visibility, _traced_method_name(method_name, metric_name_code) ::TingYun::Agent.logger.debug("Traced method: class = #{self.name},"+ "method = #{method_name}, "+ "metric = '#{metric_name_code}'") end |