Rack::RequestId
Rack middleware which adds a 16-digit hexidecimal X-Request-Id header
to the response and into Thread.current[:request_id]
Usage
gem 'rack-request-id'
Sinatra
class MyApp < Sinatra::Base
use Rack::RequestId
end
Rails
module MyApp
class Application < Rails::Application
# ...
config.middleware.use "Rack::RequestId"
end
end
Configuration
Optionally you can override the ID generation proc. By default it's SecureRandom.hex(16).
class MyApp < Sinatra::Base
use Rack::RequestId, id_generator: proc { SecureRandom.random_number(100) }
end
Optionally you can also change storage. Storage objects must have #[] and #[]= method.
require 'request_store'
class MyApp < Sinatra::Base
use Rack::RequestId, storage: RequestStore
end
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request