Class: RailsInstrument::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_instrument.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Middleware

Returns a new instance of Middleware.



39
40
41
# File 'lib/rails_instrument.rb', line 39

def initialize(app, options = {})
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rails_instrument.rb', line 43

def call(env)
  RailsInstrument.reset!
  status, headers, body = @app.call(env)
  begin
    headers["X-View-Runtime"] = (RailsInstrument.data["process_action.action_controller"][:view_runtime] / 1000).to_s
    headers["X-DB-Runtime"] = (RailsInstrument.data["process_action.action_controller"][:db_runtime] / 1000).to_s
    headers["X-DB-Query-Count"] = RailsInstrument.sql_count.to_s
  rescue => e
    # Do nothing
  end

  [status, headers, body]
end