Class: Rack::RequestId
- Inherits:
-
Object
- Object
- Rack::RequestId
- Defined in:
- lib/rack/request_id.rb
Overview
Public: Rack middleware that stores the Heroku-Request-Id header in a thread local variable.
Heroku has a labs feature called request_id, which can be used to tracking a request through the system.
app - The Rack app.
Examples
use Rack::LogRequestId
logger.info "request_id=#{Thread.current[:request_id]} Hello world"
# => request_id=a08a6712229fb991c0e5026c246862c7 Hello world
Constant Summary collapse
- REQUEST_HEADER =
'HTTP_HEROKU_REQUEST_ID'.freeze
- RESPONSE_HEADER =
'X-Request-Id'.freeze
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ RequestId
constructor
A new instance of RequestId.
Constructor Details
#initialize(app, options = {}) ⇒ RequestId
Returns a new instance of RequestId.
21 22 23 |
# File 'lib/rack/request_id.rb', line 21 def initialize(app, = {}) @app = app end |
Instance Method Details
#call(env) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/rack/request_id.rb', line 25 def call(env) ::RequestId.request_id = env[REQUEST_HEADER] status, headers, body = @app.call(env) headers[RESPONSE_HEADER] ||= ::RequestId.request_id [status, headers, body] ensure ::RequestId.request_id = nil end |