Module: ScoutApm::Tracer::ClassMethods

Defined in:
lib/scout_apm/tracer.rb

Instance Method Summary collapse

Instance Method Details

#instrument(type, name, options = {}, &block) ⇒ Object

See ScoutApm::Tracer.instrument



43
44
45
# File 'lib/scout_apm/tracer.rb', line 43

def instrument(type, name, options={}, &block)
  ScoutApm::Tracer.instrument(type, name, options, &block)
end

#instrument_method(method_name, options = {}) ⇒ Object

Wraps a method in a call to #instrument via aggressive monkey patching.

Options: type - “View” or “ActiveRecord” and similar name - “users/show”, “App#find”



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/scout_apm/tracer.rb', line 52

def instrument_method(method_name, options = {})
  ScoutApm::Agent.instance.context.logger.info "Instrumenting #{method_name}"
  type = options[:type] || "Custom"
  name = options[:name] || "#{self.name}/#{method_name.to_s}"

  instrumented_name, uninstrumented_name = _determine_instrumented_name(method_name, type)

  ScoutApm::Agent.instance.context.logger.info "Instrumenting #{instrumented_name}, #{uninstrumented_name}"

  return if !_instrumentable?(method_name) or _instrumented?(instrumented_name, method_name)

  class_eval(
    _instrumented_method_string(instrumented_name, uninstrumented_name, type, name, {:scope => options[:scope] }),
    __FILE__, __LINE__
  )

  alias_method uninstrumented_name, method_name
  alias_method method_name, instrumented_name
end