Class: RailsInstrument::Middleware

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Middleware.



5
6
7
# File 'lib/rails_instrument.rb', line 5

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

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rails_instrument.rb', line 9

def call(env)
  $rails_instrument = {}
  status, headers, body = @app.call(env)
  begin
    headers["X-View-Runtime"] = ($rails_instrument["process_action.action_controller"][:view_runtime] / 1000).to_s
    headers["X-DB-Runtime"] = ($rails_instrument["process_action.action_controller"][:db_runtime] / 1000).to_s
    headers["X-DB-Query-Count"] = $rails_instrument[:sql_count].to_s
  rescue
    # Do nothing
  end

  [status, headers, body]
end