Module: ScoutRails::Tracer::ClassMethods
- Defined in:
- lib/scout_rails/tracer.rb
Instance Method Summary collapse
-
#instrument(metric_name, options = {}, &block) ⇒ Object
Options: - :scope => If specified, sets the sub-scope for the metric.
- #instrument_method(method, options = {}) ⇒ Object
-
#trace(metric_name, options = {}, &block) ⇒ Object
Use to trace a method call, possibly reporting slow transaction traces to Scout.
Instance Method Details
#instrument(metric_name, options = {}, &block) ⇒ Object
Options:
-
:scope => If specified, sets the sub-scope for the metric. We allow additional scope level. This is used
when rendering the transaction tree in the UI.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/scout_rails/tracer.rb', line 29 def instrument(metric_name, ={}, &block) # don't instrument if (1) NOT inside a transaction and (2) NOT a Controller metric. if !Thread::current[:scout_scope_name] and metric_name !~ /\AController\// ScoutRails::Agent.instance.logger.debug "Not instrumenting [#{metric_name}] - no scope." return yield end if .delete(:scope) Thread::current[:scout_sub_scope] = metric_name end stack_item = ScoutRails::Agent.instance.store.record(metric_name) begin yield ensure Thread::current[:scout_sub_scope] = nil if Thread::current[:scout_sub_scope] == metric_name ScoutRails::Agent.instance.store.stop_recording(stack_item,) end end |
#instrument_method(method, options = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/scout_rails/tracer.rb', line 47 def instrument_method(method, = {}) ScoutRails::Agent.instance.logger.info "Instrumenting #{method}" metric_name = [:metric_name] || default_metric_name(method) return if !instrumentable?(method) or instrumented?(method,metric_name) class_eval instrumented_method_string(method, {:metric_name => metric_name, :scope => [:scope]}), __FILE__, __LINE__ alias_method _uninstrumented_method_name(method, metric_name), method alias_method method, _instrumented_method_name(method, metric_name) end |
#trace(metric_name, options = {}, &block) ⇒ Object
Use to trace a method call, possibly reporting slow transaction traces to Scout.
17 18 19 20 21 22 23 24 |
# File 'lib/scout_rails/tracer.rb', line 17 def trace(metric_name, = {}, &block) ScoutRails::Agent.instance.store.reset_transaction! instrument(metric_name, ) do Thread::current[:scout_scope_name] = metric_name yield Thread::current[:scout_scope_name] = nil end end |