Donald Plummer's Blog


Request guids for rails services and logging

23 Apr 2015

One of the most important aspects of a running system are it's logs. At work we have many difference Rails apps running, communicating to each other over a JSON HTTP API. To troubleshoot problems, I've developed some standards for setting up logging.

The important points:


In the Gemfile, add these gems:

gem 'http_logger'
gem 'request_id'
gem 'rack_set_request_id'
gem 'lograge'

Assuming you're using honeybadger, configure http_logger's initializer to ignore those requests. I've set log_headers to false, though that is the default. It's helpful sometimes to turn that on when debugging this, just to make sure the ReqeustID is being passed properly.

if defined?(HttpLogger)
  HttpLogger.ignore = [/honeybadger\.io/, /:8080/]
  HttpLogger.log_headers = false

For any Faraday client connections, use the request_id gem:

require 'faraday/request_id'

connection = '' do |builder|
  builder.use Faraday::RequestId

Configure your environments to use tagged logging and lograge, like config/environments/production.rb:

  # Configure lograge
  config.log_level = :debug
  config.lograge.enabled = true
  config.log_tags = [
    ->(_request) { "%s#%s".freeze % ["%Y-%m-%dT%H:%M:%S.%6N ".freeze),] },
    :uuid ]
  config.logger =

If you use a load balancer, or have a monitoring service that hits a specific path, and you don't want that logged, check out my previous blog post about a log silencer.