Module: Sequel::Plugins::OneapmInstrumentation::MethodTracer

Included in:
ClassMethods, InstanceMethods
Defined in:
lib/sequel/plugins/oneapm_instrumentation.rb

Instance Method Summary collapse

Instance Method Details

#add_method_tracer(method_name, metric = nil, options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sequel/plugins/oneapm_instrumentation.rb', line 25

def add_method_tracer( method_name, metric=nil, options={} )
  # Shift options hash if metric is omitted
  if metric.is_a?( Hash )
    options = metric
    metric = nil
  end

  metric ||= method_name.to_s

  body = make_tracer_method( metric, options )
  define_method( method_name, &body )
end

#make_tracer_method(opname, options) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/sequel/plugins/oneapm_instrumentation.rb', line 12

def make_tracer_method( opname, options )
  body = Proc.new do |*args, &block|
    classname = self.is_a?( Class ) ? self.name : self.class.name
    op_name = OneApm::Agent::Instrumentation::ActiveRecordHelper.rename_for(opname)
    metrics = OneApm::Agent::Instrumentation::ActiveRecordHelper.metric_for(classname, op_name).compact
    trace_execution_scoped( metrics, options ) do
      super( *args, &block )
    end
  end

  return body
end