Timber v0.2.3 Timber.PlugUtils

Summary

Functions

Fetches the request ID from the connection using the given header name

Functions

get_request_id(conn, header_name)
get_request_id(Plug.Conn.t, String.t) ::
  [{String.t, String.t}] |
  []

Fetches the request ID from the connection using the given header name

The request ID may be added to the connection in a number of ways which complicates how we retrieve it. It is usually set by calling the Plug.RequestId module on the connection which sets a request ID only if one hasn’t already been set. If the request ID is set by a service prior to Plug, it will be present as a request header. If Plug.RequestId generates a request ID, that request ID is only present in the response headers. The request headers should always take precedent in this function, though.

This function will return either a single element list containing a two-element tuple of the form:

{“x-request-id”, “myrequestid91391”}

or an empty list. This normalizes the expectation of the header name for future processing.

Note: Plug.RequestId will change an existing request ID if it doesn’t think the request ID is valid. See request_id.ex.