Class: Lens::Rails::RequestScopeMiddleware
- Inherits:
-
Object
- Object
- Lens::Rails::RequestScopeMiddleware
- Defined in:
- lib/lens/rails/requests_exporter.rb
Overview
Tiny Rack middleware that opens a per-request operation accumulator so SQL and view notifications can attach to the right request on the current thread.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ RequestScopeMiddleware
constructor
A new instance of RequestScopeMiddleware.
Constructor Details
#initialize(app) ⇒ RequestScopeMiddleware
Returns a new instance of RequestScopeMiddleware.
12 13 14 |
# File 'lib/lens/rails/requests_exporter.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 26 27 28 29 30 31 32 |
# File 'lib/lens/rails/requests_exporter.rb', line 16 def call(env) wall_start = Time.now Thread.current[:lens_request_id] = env["action_dispatch.request_id"] Thread.current[:lens_request_ops] = [] Thread.current[:lens_request_start] = Process.clock_gettime(Process::CLOCK_MONOTONIC) Thread.current[:lens_request_wall_start] = wall_start Thread.current[:lens_queue_time_ms] = parse_queue_time(env, wall_start) @app.call(env) ensure Thread.current[:lens_request_id] = nil Thread.current[:lens_request_ops] = nil Thread.current[:lens_request_start] = nil Thread.current[:lens_request_wall_start] = nil Thread.current[:lens_queue_time_ms] = nil Thread.current[:lens_controller] = nil Thread.current[:lens_action] = nil end |