Class: LogStruct::Integrations::RequestContext::Middleware

Inherits:
LogStruct::Integrations::RackMiddleware show all
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

Methods inherited from LogStruct::Integrations::RackMiddleware

#initialize

Constructor Details

This class inherits a constructor from LogStruct::Integrations::RackMiddleware

Instance Method Details

#call(env) ⇒ T.untyped

Parameters:

  • env (T.untyped)

Returns:

  • (T.untyped)


13
14
15
16
17
18
19
20
21
22
# File 'lib/log_struct/integrations/request_context/middleware.rb', line 13

def call(env)
  request = ::ActionDispatch::Request.new(env)
  request_id = request.request_id
  Thread.current[:logstruct_request_id] = request_id
  ::SemanticLogger.push_named_tags(request_id: request_id)
  @app.call(env)
ensure
  ::SemanticLogger.pop_named_tags
  Thread.current[:logstruct_request_id] = nil
end