Class: RequestTracer

Inherits:
Object
  • Object
show all
Defined in:
app/middleware/request_tracer.rb

Overview

Author Azitabh Ajit

This is a middleware to expose request id set by 
This capability is added in rails 5 by default and is available by Current.request_id https://github.com/rails/rails/commit/24a864437e845febe91e3646ca008e8dc7f76b56
This usage threadlocal to make the request id available to the whole app just the way it's managed in later versions of rails :https://github.com/rails/rails/commit/24a864437e845febe91e3646ca008e8dc7f76b56#diff-3c3c0f647bc4702f9453c173a707aa06R90
This won't be required once we migrate to rails 5 or beyond

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RequestTracer

Returns a new instance of RequestTracer.



10
11
12
# File 'app/middleware/request_tracer.rb', line 10

def initialize app
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



14
15
16
17
18
# File 'app/middleware/request_tracer.rb', line 14

def call env
  Thread.current[:global_request_id] =  env["action_dispatch.request_id"]
  @status, @headers, @response = @app.call env
  [@status, @headers, @response]
end