# `Zexbox.Metrics`
[🔗](https://github.com/Intellection/zexbox/blob/main/lib/zexbox/metrics.ex#L1)

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.

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

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `disable_for_process`

```elixir
@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?`

```elixir
@spec disabled?() :: boolean()
```

Returns true if the current process has disabled metrics.

# `enable_for_process`

```elixir
@spec enable_for_process() :: :ok
```

Re-enables metric writing for the current process.

# `init`

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`

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

Starts the metrics supervisor and attaches the controller metrics.

Accepts an optional `:enricher` to customise the controller series before it
is written. See `Zexbox.Metrics.ControllerSeriesEnricher`.

    children = [
      {Zexbox.Metrics, enricher: {MyApp.MetricsEnricher, []}}
    ]

An enricher can also be set via application env
(`config :zexbox, :metrics_enricher, {MyApp.MetricsEnricher, []}`); the
`start_link/1` argument wins if both are present.

## Examples

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
