Sha256: b33f43488980c5649f37590294feb46ba4f3435e620fa31feebc9c3e16710a90

Contents?: true

Size: 1.88 KB

Versions: 3

Compression:

Stored size: 1.88 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
            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

        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, :delete
        add_method_tracer :update
        add_method_tracer :update_all, :update
        add_method_tracer :update_except, :update
        add_method_tracer :update_fields, :update
        add_method_tracer :update_only, :update
        add_method_tracer :save, :insert

      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

3 entries across 3 versions & 1 rubygems

Version Path
oneapm_rpm-1.4.2 lib/sequel/plugins/oneapm_instrumentation.rb
oneapm_rpm-1.4.1 lib/sequel/plugins/oneapm_instrumentation.rb
oneapm_rpm-1.4.0 lib/sequel/plugins/oneapm_instrumentation.rb