time_log v0.1.2 TimeLog.TimePlug

This plug stops the time a request takes. The plug needs to be called as early in the endpoint.ex as possible, ideally right after the socked received a request. Additionally the get_duration function can be called from everywhere in order to know how long the request took so far. Allows calls to get_ip from other apps too.

Link to this section Summary

Functions

Call to TimePlug that initiates the duration measurement and schedules Response logging to take place before sending the response

Returns the time in ms the request took so far. May be called with either a Time struct Time or with the current conn Plug.Conn

Returns the IP address in a Format fit for logging. If set in config the IP addresses retourned are anonymized by replacing the last digits with ‘XXX’. Requests that use internal (e.g. company) Ip addresses can be filtered if set in config(config :time_log, internal_ips: ["127.0.0.1"])

Log the response including the IP address, correlation_id and headers

Link to this section Functions

Link to this function call(conn, opts)
call(Plug.Conn, Map) :: Plug.Conn

Call to TimePlug that initiates the duration measurement and schedules Response logging to take place before sending the response.

Link to this function get_duration(start_time)
get_duration(Plug.Conn) :: Time
get_duration(Time) :: Integer

Returns the time in ms the request took so far. May be called with either a Time struct Time or with the current conn Plug.Conn.

Examples

iex> TimeLog.TimePlug.get_duration(conn) # Request the duration with a [`Plug.Conn`](https://hexdocs.pm/plug/1.4.3/Plug.Conn.html) struct
65

iex> start_time = Time.utc_now
...
...
iex> TimeLog.TimePlug.get_duration(start_time) # Request the duration with a [`Time`](https://hexdocs.pm/elixir/Time.html) struct
65
Link to this function get_ip(conn)
get_ip(Plug.Conn) :: String

Returns the IP address in a Format fit for logging. If set in config the IP addresses retourned are anonymized by replacing the last digits with ‘XXX’. Requests that use internal (e.g. company) Ip addresses can be filtered if set in config(config :time_log, internal_ips: ["127.0.0.1"]).

Link to this function log_response(conn, start_time)
log_response(Plug.Conn, Time) :: Plug.Conn

Log the response including the IP address, correlation_id and headers.