Timber v1.0.5 Timber.Events.HTTPClientRequestEvent
The HTTPClientRequestEvent
tracks outgoing HTTP requests giving you structured insight
into communication with external services.
This event is HTTP client agnostic, use it with your HTTP client of choice.
Hackney Example
req_method = :get
req_url = "https://some.api.com/path?query=1"
req_headers = [{"Accept", "application/json"}]
# Log the outgoing request
{req_event, req_message} = Timber.Events.HTTPClientRequestEvent.new_with_message(method: req_method, url: req_url, headers: req_headers)
Logger.info req_message, event: req_event
# Make the request
timer = Timber.Timer.start()
{:ok, status, headers, body} = :hackney.request(req_method, req_url, req_headers, "")
# Log the response
{resp_event, resp_message} = Timber.Events.HTTPClientResponseEvent.new(headers: headers, status: status, timer: timer)
Logger.info resp_message, event: resp_event
Summary
Functions
Message to be used when logging. The format looks like
Builds a new struct taking care to normalize data into a valid state. This should be used, where possible, instead of creating the struct directly
Convenience methods for creating an event and getting the message at the same time
Types
Functions
Message to be used when logging. The format looks like:
Outgoing HTTP request to :service_name [GET] /path, ID: :request_id
Taking care to format the string properly if optional attributes like :service_name
and
:request_id
are not present.
Builds a new struct taking care to normalize data into a valid state. This should be used, where possible, instead of creating the struct directly.
Convenience methods for creating an event and getting the message at the same time.