Class: ScoutApm::Instruments::ActiveRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/instruments/active_record.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



6
7
8
# File 'lib/scout_apm/instruments/active_record.rb', line 6

def logger
  @logger
end

Instance Method Details

#add_instrumentsObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/scout_apm/instruments/active_record.rb', line 29

def add_instruments
  if defined?(::ActiveRecord) && defined?(::ActiveRecord::Base)
    ::ActiveRecord::ConnectionAdapters::AbstractAdapter.module_eval do
      include ::ScoutApm::Instruments::ActiveRecordInstruments
      include ::ScoutApm::Tracer
    end

    ::ActiveRecord::Base.class_eval do
      include ::ScoutApm::Tracer
    end
  end
rescue
  ScoutApm::Agent.instance.logger.warn "ActiveRecord instrumentation exception: #{$!.message}"
end

#initalize(logger = ScoutApm::Agent.instance.logger) ⇒ Object



8
9
10
11
# File 'lib/scout_apm/instruments/active_record.rb', line 8

def initalize(logger=ScoutApm::Agent.instance.logger)
  @logger = logger
  @installed = false
end

#installObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/scout_apm/instruments/active_record.rb', line 17

def install
  @installed = true

  if defined?(::Rails) && ::Rails::VERSION::MAJOR.to_i == 3 && ::Rails.respond_to?(:configuration)
    Rails.configuration.after_initialize do
      add_instruments
    end
  else
    add_instruments
  end
end

#installed?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/scout_apm/instruments/active_record.rb', line 13

def installed?
  @installed
end