Class: Spokes::Middleware::RequestID
- Inherits:
-
Object
- Object
- Spokes::Middleware::RequestID
- Defined in:
- lib/spokes/middleware/request_id.rb
Constant Summary collapse
- PATTERN =
/^[\w\\-_\\.\d]+$/
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, service_name:) ⇒ RequestID
constructor
A new instance of RequestID.
Constructor Details
Instance Method Details
#call(env) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/spokes/middleware/request_id.rb', line 13 def call(env) id = env['action_dispatch.request_id'] || SecureRandom.uuid request_ids = extract_request_ids(env).insert(0, @service_name + ':' + id) # make ID of the request accessible to consumers down the stack env['REQUEST_ID'] = request_ids[0] # Extract request IDs from incoming headers as well. Can be used for # identifying a request across a number of components in SOA. env['REQUEST_IDS'] = request_ids Thread.current[:request_chain] = env['REQUEST_IDS'] @app.call(env) end |