Sha256: 8c4353bb5bf362f0e94db1abe83147f132adbd2489d459c9d4b1b897167c3512

Contents?: true

Size: 1.69 KB

Versions: 2

Compression:

Stored size: 1.69 KB

Contents

# 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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
oneapm_rpm-1.1.1 lib/sequel/plugins/oneapm_instrumentation.rb
oneapm_rpm-1.1.0 lib/sequel/plugins/oneapm_instrumentation.rb