Module: ScoutApm::Instruments::ActiveRecordInstruments

Defined in:
lib/scout_apm/instruments/active_record.rb

Overview

Contains ActiveRecord instrument, aliasing ActiveRecord::ConnectionAdapters::AbstractAdapter#log calls to trace calls to the database.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(instrumented_class) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/scout_apm/instruments/active_record.rb', line 48

def self.included(instrumented_class)
  ScoutApm::Agent.instance.logger.info "Instrumenting #{instrumented_class.inspect}"
  instrumented_class.class_eval do
    unless instrumented_class.method_defined?(:log_without_scout_instruments)
      alias_method :log_without_scout_instruments, :log
      alias_method :log, :log_with_scout_instruments
      protected :log
    end
  end
end

Instance Method Details

#log_with_scout_instruments(*args, &block) ⇒ Object

self.included



59
60
61
62
63
64
65
66
# File 'lib/scout_apm/instruments/active_record.rb', line 59

def log_with_scout_instruments(*args, &block)
  sql, name = args
  self.class.instrument("ActiveRecord",
                        Utils::ActiveRecordMetricName.new(sql, name),
                        :desc => Utils::SqlSanitizer.new(sql) ) do
    log_without_scout_instruments(sql, name, &block)
  end
end