Class: HookDeck::Middleware::RequestId
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- HookDeck::Middleware::RequestId
- Defined in:
- lib/hookdeck/middlewares/request_id.rb
Overview
Middleware that automatically generates and manages request IDs for HTTP requests. Adds both server and client request IDs to facilitate request tracking and debugging.
Instance Method Summary collapse
-
#call(env) ⇒ Object
Executes the middleware, adding and tracking request IDs.
-
#initialize(app, options = {}) ⇒ RequestId
constructor
Initialize the request ID middleware.
Constructor Details
#initialize(app, options = {}) ⇒ RequestId
Initialize the request ID middleware
13 14 15 16 |
# File 'lib/hookdeck/middlewares/request_id.rb', line 13 def initialize(app, = {}) super(app) @prefix = .fetch(:prefix, 'req') end |
Instance Method Details
#call(env) ⇒ Object
Executes the middleware, adding and tracking request IDs
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/hookdeck/middlewares/request_id.rb', line 19 def call(env) env.request_headers['X-Request-Id'] ||= generate_request_id env.request_headers['X-Client-Request-Id'] ||= generate_request_id @app.call(env).on_complete do |response_env| # Store request IDs for potential error handling response_env[:hookdeck_request_id] = response_env.response_headers['x-request-id'] response_env[:hookdeck_client_request_id] = env.request_headers['X-Client-Request-Id'] end end |