Repository is archived
No commit activity in last 3 years
No release in over 3 years
RequestHeaderLogger Allows you to tag logs with RequestHeader flags.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 4.1.4, ~> 4.1
>= 1.6.5, ~> 1.6
>= 12.0.0, ~> 12.0
>= 3.5.0, ~> 3.5
~> 0.53.0
~> 0.12.0

Runtime

 Project Readme

RequestHeaderLogger

RequestHeaderLogger Allows you to tag logs with RequestHeader flags

In micro-service architecture it is very important to be able to corroborate logs from different services for a specific request. The correlation must include both services connected synchronously or asynchronously.

For this issue the X-Request-Id HTTP header was introduced. In Rails the ActionDispatch::RequestId middleware helps create a unique ID for each request if not already defined by the X-Request-Id header. In addition, RequestHeaderMiddleware will allow you to share the same 'X-Request-Id' for multiple requests and multiple services.

Unfortunately, Using RequestHeaderMiddleware and ActionDispatch::RequestId do not solve the Issues completely. RequestHeaderMiddleware will share the X-Request-Id only with synchronous requests.

The gem can be used to share RequestHeader store items the asynchronous services (Delayed Jobs). The default is the while listed item is X-Request-Id. However, It is possible to extend the whilelist with more items.

Installation

Rails

So how does it work with Rails.

Add this line to your application's Gemfile after the delayed job and message_queue gems:

gem 'request_headers_logger'

And then execute:

$ bundle

That's it now Delayed job logs should show the X-Request-Id from the http request.

Configure RequestHeadersLogger

RequestHeadersLogger.configure do |config|
  config[:logger_format] = 'json'         # Options [text json] default: text
  config[:tag_format] = 'key_val'         # Options: [val key_val] default: val
end

Whitelist

Per default the delayed job plug in applies a whitelist to only filter X-Request-Id header from the store. To white list new flags, you can do the following.

 RequestHeadersLogger.whitelist << "customer-id".to_sym