Class: Rack::Ougai::AttachRequestID
- Inherits:
-
Object
- Object
- Rack::Ougai::AttachRequestID
- Defined in:
- lib/rack/ougai/attach_request_id.rb
Constant Summary collapse
- REQUEST_ID_KEY =
'HTTP_X_REQUEST_ID'
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, opts = {}) ⇒ AttachRequestID
constructor
A new instance of AttachRequestID.
Constructor Details
#initialize(app, opts = {}) ⇒ AttachRequestID
Returns a new instance of AttachRequestID.
8 9 10 11 |
# File 'lib/rack/ougai/attach_request_id.rb', line 8 def initialize(app, opts = {}) @app = app @storage = opts[:storage] || proc { Thread.current } end |
Instance Method Details
#call(env) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rack/ougai/attach_request_id.rb', line 13 def call(env) parent = env[Rack::RACK_LOGGER] request_id = env[REQUEST_ID_KEY] if request_id.nil? parent.warn "No request ID in storage (is Rack::RequestID in your middleware stack?)." end env[Rack::RACK_LOGGER] = parent.child(request_id: request_id) ret = @app.call(env) env[Rack::RACK_LOGGER] = parent ret end |