Timber v1.0.2 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

headers()
headers :: %{accept: String.t | nil, content_type: String.t | nil, request_id: String.t | nil, user_agent: String.t | nil}
t()
t :: %Timber.Events.HTTPClientRequestEvent{headers: headers | nil, host: String.t, method: String.t, path: String.t, port: pos_integer | nil, query_string: String.t | nil, scheme: String.t, service_name: String.t | nil}

Functions

message(h_t_t_p_client_request_event)
message(t) :: IO.chardata

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.

new(opts)
new(Keyword.t) :: t

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.

new_with_message(opts)
new_with_message(Keyword.t) :: {t, IO.chardata}

Convenience methods for creating an event and getting the message at the same time.