Monitorex.Event
(monitorex v0.3.0)
Copy Markdown
Represents a monitored HTTP event (inbound or outbound).
Contains all relevant fields for recording and displaying HTTP telemetry data collected from Tesla, Finch, and Phoenix telemetry events.
Summary
Functions
Classifies an HTTP status code into a status class atom.
Converts a time value from the native time unit to milliseconds as a float.
Extracts the host from a URI.t() struct or a URL string.
Normalizes a method atom (or string) to an uppercase string.
Types
@type t() :: %Monitorex.Event{ consumer: String.t() | nil, dedup_key: term(), direction: :inbound | :outbound, duration_ms: float(), error: String.t() | nil, full_url: String.t() | nil, host: String.t() | nil, method: String.t(), path: String.t() | nil, request_body: binary() | nil, request_headers: [{atom() | String.t(), String.t()}] | nil, response_body: binary() | nil, response_headers: [{atom() | String.t(), String.t()}] | nil, source: atom(), status: non_neg_integer() | nil, status_class: atom(), timestamp: integer() }
Functions
@spec classify_status(status :: integer()) :: :success | :redirect | :client_error | :server_error | :default
Classifies an HTTP status code into a status class atom.
Examples
iex> Monitorex.Event.classify_status(200)
:success
iex> Monitorex.Event.classify_status(301)
:redirect
iex> Monitorex.Event.classify_status(404)
:client_error
iex> Monitorex.Event.classify_status(500)
:server_error
Converts a time value from the native time unit to milliseconds as a float.
Examples
iex> Monitorex.Event.duration_ms(1_000_000)
1.0
iex> Monitorex.Event.duration_ms(0)
0.0
Extracts the host from a URI.t() struct or a URL string.
Examples
iex> Monitorex.Event.extract_host(%URI{host: "example.com"})
"example.com"
iex> Monitorex.Event.extract_host("https://api.example.com/path")
"api.example.com"
iex> Monitorex.Event.extract_host(%URI{host: nil})
nil
Normalizes a method atom (or string) to an uppercase string.
Tesla and Finch pass method as atoms (:get, :post); this converts
them to the conventional uppercase form ("GET", "POST").
Examples
iex> Monitorex.Event.normalize_method(:get)
"GET"
iex> Monitorex.Event.normalize_method(:post)
"POST"
iex> Monitorex.Event.normalize_method("GET")
"GET"