# `Tinkex.Metrics`
[🔗](https://github.com/North-Shore-AI/tinkex/blob/v0.4.0/lib/tinkex/metrics.ex#L1)

Lightweight metrics aggregation for Tinkex telemetry events.

The server subscribes to `[:tinkex, :http, :request, :stop]` and keeps
counters for successes/failures plus latency histograms. Public helpers allow
recording custom counters, gauges, and histograms for experiment tracking.

# `histogram_snapshot`

```elixir
@type histogram_snapshot() :: %{
  count: non_neg_integer(),
  mean: float() | nil,
  min: float() | nil,
  max: float() | nil,
  p50: float() | nil,
  p95: float() | nil,
  p99: float() | nil
}
```

# `metric_name`

```elixir
@type metric_name() :: atom()
```

# `snapshot`

```elixir
@type snapshot() :: %{
  counters: %{optional(metric_name()) =&gt; number()},
  gauges: %{optional(metric_name()) =&gt; number()},
  histograms: %{optional(metric_name()) =&gt; histogram_snapshot()}
}
```

# `flush`

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

Block until the server has processed all prior casts.

# `handle_event`

```elixir
@spec handle_event([atom()], map(), map(), term()) :: :ok
```

Telemetry handler entrypoint.

# `increment`

```elixir
@spec increment(metric_name(), number()) :: :ok
```

Increment a counter metric by the provided delta (default: 1).

# `record_histogram`

```elixir
@spec record_histogram(metric_name(), number()) :: :ok
```

Record a histogram sample (value in milliseconds).

# `reset`

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

Reset all metrics state.

# `set_gauge`

```elixir
@spec set_gauge(metric_name(), number()) :: :ok
```

Set a gauge to a specific value.

# `snapshot`

```elixir
@spec snapshot() :: snapshot()
```

Return a snapshot of counters, gauges, and histograms.

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

Start the metrics server.

Options:
  * `:enabled` - turn metrics on/off (defaults to application env, true)
  * `:latency_buckets` - histogram buckets in milliseconds

---

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