Module: ScoutApm::Tracer::ClassMethods

Defined in:
lib/scout_apm/tracer.rb

Instance Method Summary collapse

Instance Method Details

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

Type: the Layer type - “View” or similar Name: specific name - “users/_gravatar”. The object must respond to “#to_s”. This allows us to be more efficient - in most cases, the metric name isn’t needed unless we are processing a slow transaction. A Block: The code to be instrumented

Options:

  • :ignore_children - will not instrument any method calls beneath this call. Example use case: InfluxDB uses Net::HTTP, which is instrumented. However, we can provide more specific data if we know we’re doing an influx call, so we’d rather just instrument the Influx call and ignore Net::HTTP. when rendering the transaction tree in the UI.

  • :desc - Additional capture, SQL, or HTTP url or similar

  • :scope - set to true if you want to make this layer a subscope



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/scout_apm/tracer.rb', line 25

def instrument(type, name, options={}) # Takes a block
  layer = ScoutApm::Layer.new(type, name)
  layer.desc = options[:desc] if options[:desc]
  layer.subscopable!          if options[:scope]

  req = ScoutApm::RequestManager.lookup
  req.start_layer(layer)
  req.ignore_children! if options[:ignore_children]

  begin
    yield
  ensure
    req.stop_layer
    req.acknowledge_children! if options[:ignore_children]
  end
end

#instrument_method(method, 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”



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/scout_apm/tracer.rb', line 47

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

  return if !instrumentable?(method) or instrumented?(method, type, name)

  class_eval(
    instrumented_method_string(method, type, name, {:scope => options[:scope] }),
    __FILE__, __LINE__
  )

  alias_method _uninstrumented_method_name(method, type, name), method
  alias_method method, _instrumented_method_name(method, type, name)
end