Class: AMQPLogging::Rails::AfterDispatchCallbackHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/amqp_logging/metrics_agent/rails/after_dispatch_callback_handler.rb

Class Method Summary collapse

Class Method Details

.run(dispatcher) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/amqp_logging/metrics_agent/rails/after_dispatch_callback_handler.rb', line 4

def self.run(dispatcher)
  env = dispatcher.instance_variable_get(:@env)
  response = env["action_controller.rescue.response"]
  request = env["action_controller.rescue.request"]
  request_headers  = request.headers.dup
  request_headers.each do |k, v|
    case v
    when String, Fixnum, Numeric
    else
      request_headers[k] = "#<#{v.class.name}>"
    end
  end
  agent = ActionController::Base.logger.agent
  agent.fields.merge!({
    :env => RAILS_ENV,
    :response_code    => response.status,
    :request_params   => request.request_parameters,
    :request_headers  => request_headers,
    :response_headers => response.headers
  })
  agent.flush
end