Class: Metrician::Middleware::ApplicationTiming

Inherits:
Object
  • Object
show all
Defined in:
lib/metrician/middleware/application_timing.rb

Overview

RequestTiming and ApplicationTiming work in concert to time the middleware separate from the request processing. RequestTiming should be the first or near first middleware loaded since it will be timing from the moment the the app server is hit and setting up the env for tracking the middleware execution time. RequestTiming should be the last or near last middleware loaded as it times the application execution (separate from middleware).

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ApplicationTiming

Returns a new instance of ApplicationTiming.



12
13
14
# File 'lib/metrician/middleware/application_timing.rb', line 12

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/metrician/middleware/application_timing.rb', line 16

def call(env)
  if Middleware.request_timing_required?
    start_time = Time.now.to_f
  end
  @app.call(env)
ensure
  if Middleware.request_timing_required?
    env[ENV_REQUEST_TOTAL_TIME] ||= (Time.now.to_f - start_time)
  end
end