View Source Zexbox.Metrics (Zexbox v1.5.1)

This module is esponsible for setting up and supervising the metrics collection and telemetry. It attaches telemetry handlers for capturing metrics related to your Phoenix endpoints.

def start(_type, args) do
  children = [{Zexbox.Metrics, []}]
  Supervisor.start_link(children, opts)
end

Summary

Functions

Returns a specification to start this module under a supervisor.

Disables metric writing for the current process. Writes from this process (and from tasks spawned with Task.async that have this process in $callers) will be skipped until enable_for_process/0 is called or the process exits.

Returns true if the current process has disabled metrics.

Re-enables metric writing for the current process.

Initializes the supervisor with the required child processes.

Starts the metrics supervisor and attaches the controller metrics.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

disable_for_process()

@spec disable_for_process() :: :ok

Disables metric writing for the current process. Writes from this process (and from tasks spawned with Task.async that have this process in $callers) will be skipped until enable_for_process/0 is called or the process exits.

Use this in a Plug or elsewhere when you want to suppress metrics for a request (e.g. when a header indicates a test or health check).

disabled?()

@spec disabled?() :: boolean()

Returns true if the current process has disabled metrics.

enable_for_process()

@spec enable_for_process() :: :ok

Re-enables metric writing for the current process.

init(args)

Initializes the supervisor with the required child processes.

Examples

iex> Zexbox.Metrics.init(nil)
{:ok,
 {%{intensity: 3, period: 5, strategy: :one_for_one, auto_shutdown: :never},
  [
    %{id: Zexbox.Metrics.ContextRegistry, ...},
    %{
      id: Zexbox.Metrics.Connection,
      start: {Instream.Connection.Supervisor, :start_link, [Zexbox.Metrics.Connection]}
    }
  ]}}

start_link(args)

@spec start_link(args :: any()) :: Supervisor.on_start()

Starts the metrics supervisor and attaches the controller metrics.

Examples

  iex> Zexbox.Metrics.start_link(nil)
  {:ok, #PID<0.123.0>}