Module: AllSeeingEye::Integrations::Rails2

Defined in:
lib/all_seeing_eye/integrations/rails2.rb

Instance Method Summary collapse

Instance Method Details

#log_requestObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/all_seeing_eye/integrations/rails2.rb', line 4

def log_request
  _start_time = DateTime.now
  yield
  _end_time = DateTime.now
  hash = {}
  begin
    Timeout::timeout(AllSeeingEye.configuration['timeout']) {
      AllSeeingEye::Request.fields.each do |field, options|
        object = options['object'] == 'controller' ? 'self' : options['object']
        val = eval("#{object}#{options['method']}")
        hash[field] = val
      end
      hash['created_at'] = _end_time
      hash['time_spent'] = (_end_time - _start_time).to_f * 1000
      AllSeeingEye::Request.create(hash)
      Rails.logger.info('+++ Request watched by AllSeeingEye')
    }
  rescue Timeout::Error, Errno::EAGAIN
    Rails.logger.info('+++ Request not watched by AllSeeingEye; it took too long to complete or the server was unreachable')
  end
end