Class: Pinot::RequestIdMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/pinot/railtie.rb

Overview

Rack middleware that captures X-Request-Id from the inbound HTTP request and stores it in a thread-local for the duration of the request.

Inserted automatically by Pinot::Railtie. For non-Rails Rack apps:

use Pinot::RequestIdMiddleware

Constant Summary collapse

RACK_HEADER =
"HTTP_X_REQUEST_ID".freeze

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RequestIdMiddleware

Returns a new instance of RequestIdMiddleware.



82
83
84
# File 'lib/pinot/railtie.rb', line 82

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



86
87
88
89
90
91
# File 'lib/pinot/railtie.rb', line 86

def call(env)
  Thread.current[:pinot_request_id] = env[RACK_HEADER]
  @app.call(env)
ensure
  Thread.current[:pinot_request_id] = nil
end