Class: ManageEngine::Instrumentation::ActiveRecordSQL

Inherits:
Object
  • Object
show all
Defined in:
lib/agent/server/instrument/active_record.rb

Instance Method Summary collapse

Instance Method Details

#instrumentObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/agent/server/instrument/active_record.rb', line 17

def instrument
  @obj = ManageEngine::APMObjectHolder.instance
  @obj.log.info "Instrumenting ActiveRecord"
  
  ActiveSupport::Notifications.subscribe('sql.active_record') do |name, start, finish, id, payload|
    begin 
      if @obj.config.sql_capture && payload[:name] != "SCHEMA" # Dropping internal schema related queries
        dbTracker = ManageEngine::Tracker::DatabaseTracker.new(payload[:name], start.to_f * 1000)
        dbTracker.sql(payload[:sql])
        dbTracker.params(payload[:binds])
        dbTracker = ManageEngine::Agent::TrackerHandler.invokeTracker(dbTracker)
        
        if dbTracker != nil
          dbTracker.finish(finish.to_f * 1000)
          
          if dbTracker.duration >= (@obj.config.sql_trace_t.to_f * 1000)
            dbTracker.sqlBacktrace(caller(10))
          end
          
          exception = payload[:exception_object]
          if exception != nil
            dbTracker.setError(exception)
          end
          
          ManageEngine::Agent::TrackerHandler.exitTracker(dbTracker)
        end
      end
    rescue Exception => e
      @obj.log.logException("Error processing #{name} payload", e)
    end
  end #subscribe
end

#nameObject



13
14
15
# File 'lib/agent/server/instrument/active_record.rb', line 13

def name
  'ActiveRecord'
end

#present?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/agent/server/instrument/active_record.rb', line 9

def present?
  defined?(::ActiveRecord::Base) && defined?(::ActiveSupport::Notifications)
end