# encoding: utf-8 require 'sequel' unless defined?(Sequel) require 'oneapm_rpm' unless defined?(OneApm) module Sequel module Plugins module OneapmInstrumentation module MethodTracer def make_tracer_method( opname, options ) body = Proc.new do |*args, &block| classname = self.is_a?( Class ) ? self.name : self.class.name metric = "ActiveRecord/%s/%s" % [ classname, opname ] trace_execution_scoped( metric, options ) do super( *args, &block ) end end return body end 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 end module InstanceMethods include OneApm::Support::MethodTracer extend Sequel::Plugins::OneapmInstrumentation::MethodTracer add_method_tracer :delete add_method_tracer :destroy add_method_tracer :update add_method_tracer :update_all add_method_tracer :update_except add_method_tracer :update_fields add_method_tracer :update_only add_method_tracer :save end module ClassMethods include OneApm::Support::MethodTracer extend Sequel::Plugins::OneapmInstrumentation::MethodTracer add_method_tracer :[], :get add_method_tracer :all add_method_tracer :first add_method_tracer :create end end end end