class RequestIdLogging::Middleware

Rack middleware for logging with request_id.

Please insert after ActionDispatch::RequestId in your application.rb like as follows.

module YourApp
  class Application < Rails::Application
    # some configurations...

    config.middleware.insert_after ActionDispatch::RequestId, RequestIdLogging::Middleware
  end
end

Public Class Methods

new(app) click to toggle source
# File lib/request_id_logging/middleware.rb, line 18
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/request_id_logging/middleware.rb, line 22
def call(env)
  request_id = env['action_dispatch.request_id']
  Thread.current[RequestIdLogging::FIBER_LOCAL_KEY] = request_id
  @app.call(env)
ensure
  Thread.current[RequestIdLogging::FIBER_LOCAL_KEY] = nil
end