HTTP Request IDs improve visibility across the application stack
February 28, 2014 by Matthew Soldo
Visibility into your application is necessary to properly analyze and troubleshoot issues as they arise. One of the key factors to good visibility is using logs as event streams and treating them as the canonical source of what happened on an app.
The challenge with using logs is to correlate events across the stack consisting of your application's code and Heroku's platform components. Today, we are releasing new functionality that makes this simple. By using the emerging
X-Request-ID convention, you can easily correlate multiple log entries to individual HTTP(s) requests.
HTTP Request IDs are now enabled on all Heroku apps.
Each HTTP request that reaches your dyno will now contain an
X-Request-ID header. Heroku will pass through existing
X-Request-ID headers if they are set by the HTTP client. For requests that lack the header, Heroku generates an ID. Your application code can read the request ID from the header and include it in logs, or use it for other purposes. Heroku will write request ID values in the logs from our routing layer as
X-Request-IDheader is an emerging convention introduced by the Rails framework. It is a standard HTTP header, however, and can be easily accessed from any language or framework running on Heroku.
For full documentation on this feature, please visit the Dev Center.
Your application code can read and log the
X-Request-ID header value, giving you further insight into end to end behavior and performance. We have provided examples implementing this in Node.js, Python, Ruby (Rack Middleware or Rails), and Java.
To get the most out of request IDs, be sure to store your logs for later search and analysis by using a logging add-on provider.
This capability will allow you to see how requests and application code may be modifying behavior through the application stack, find the source of request errors, and get improved overall visibility into the performance characteristics of your application.