Class: Core::RequestId
Overview
Add per-request tracking
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ RequestId
constructor
A new instance of RequestId.
Constructor Details
#initialize(app) ⇒ RequestId
Returns a new instance of RequestId.
9 10 11 |
# File 'lib/svcbase/middleware/requestid.rb', line 9 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/svcbase/middleware/requestid.rb', line 13 def call(env) # RequestStore gem allows us to not muck with thread local storage directly RequestStore.store[:http_request_id] = env['HTTP_X_REQUEST_ID'] || Core::Random.short_id status, headers, body = @app.call(env) headers['X-Request-Id'] ||= RequestStore.store[:http_request_id] [status, headers, body] end |