0.01
No commit activity in last 3 years
No release in over 3 years
Rack::RequestID is a Rack middleware for generating request IDs. It generates a request GUID for every request (if one was not already provided) and inserts the request ID as a response header.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
>= 0
 Project Readme

Rack::RequestID, a Rack middleware for generating request IDs

This is a simple middleware that will generate a request GUID if one was not already provided by the client or platform.

A request ID can be specified in the request (by the client or platform) by setting the X-Request-Id header, and it will be available to other middleware via the HTTP_X_REQUEST_ID key in the Rack environment hash. If a request ID was not provided, Rack::RequestID will generate one and insert it into the Rack environment. It will also insert the request ID into the X-Request-Id header of the response.

Configuration

To use Rack::RequestID, add the following to your Gemfile:

gem 'rack-requestid'

Then in config.ru:

use Rack::RequestID

Use Rack::RequestID before any middleware that needs a request ID.

There are a few options you can pass in:

  • :include_response_header determines whether to include the request ID in a response header.
  • :overwrite can be enabled to overwrite any request ID provided by the platform or client.
  • :generator can be specified to provide a custom request ID generator.

If you want to modify the options used, simply do:

use Rack::RequestID, :include_response_header => false, :generator => lambda { "#{Time.now.getutc.to_i}" }