Class: Rack::RequestId

Inherits:
Object
  • Object
show all
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_ID_HEADER =
'HTTP_HEROKU_REQUEST_ID'.freeze

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of RequestId.



20
21
22
# File 'lib/rack/request_id.rb', line 20

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

Instance Method Details

#call(env) ⇒ Object



24
25
26
27
28
29
# File 'lib/rack/request_id.rb', line 24

def call(env)
  ::RequestId.request_id = env[REQUEST_ID_HEADER]
  @app.call(env)
ensure
  ::RequestId.request_id = nil
end