Class: LogStruct::Integrations::RequestContext::Middleware
- Inherits:
-
Object
- Object
- LogStruct::Integrations::RequestContext::Middleware
- Extended by:
- T::Sig
- Defined in:
- lib/log_struct/integrations/request_context/middleware.rb
Overview
Middleware that captures request_id and stores it in SemanticLogger's named_tags so all logs during the request include the request_id.
Instance Method Summary collapse
- #call(env) ⇒ T.untyped
- #initialize(app) ⇒ void constructor
Constructor Details
#initialize(app) ⇒ void
13 14 15 |
# File 'lib/log_struct/integrations/request_context/middleware.rb', line 13 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ T.untyped
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/log_struct/integrations/request_context/middleware.rb', line 18 def call(env) request = ::ActionDispatch::Request.new(env) request_id = request.request_id Thread.current[:logstruct_request_id] = request_id ::SemanticLogger.(request_id: request_id) @app.call(env) ensure ::SemanticLogger. Thread.current[:logstruct_request_id] = nil end |