# `HuggingfaceClient.Inference.Telemetry`
[🔗](https://github.com/huggingface/huggingface_client/blob/v0.1.0/lib/huggingface_client/inference/telemetry.ex#L1)

Telemetry integration for `HuggingfaceClient`.

## Events emitted

All events share the prefix `[:huggingface_client, :request]`.

| Event | When |
|-------|------|
| `[:huggingface_client, :request, :start]` | Before the HTTP call |
| `[:huggingface_client, :request, :stop]`  | After a successful HTTP call |
| `[:huggingface_client, :request, :exception]` | If the call raises |

### Measurements

- `:duration` — wall-clock time in native units (`:stop` and `:exception` only)
- `:monotonic_time` — start time (`:start` only)

### Metadata

| Key | Description |
|-----|-------------|
| `:provider` | Provider string, e.g. `"groq"` |
| `:task` | Task string, e.g. `"conversational"` |
| `:model` | Model ID or `nil` |
| `:status` | HTTP status code (`:stop` only) |
| `:error` | Exception struct (`:exception` only) |

## Attaching a handler

    HuggingfaceClient.Inference.Telemetry.attach_default_logger()

This logs a single line per request at `:info` level using `Logger`.

## Custom handler example

    :telemetry.attach(
      "my-hf-metrics",
      [:huggingface_client, :request, :stop],
      fn _event, %{duration: duration}, %{provider: provider, task: task}, _ ->
        MyMetrics.histogram("hf_inference.request_duration",
          duration,
          tags: [provider: provider, task: task]
        )
      end,
      nil
    )

# `attach_default_logger`

```elixir
@spec attach_default_logger(atom()) :: :ok
```

Attaches a default structured logger handler.

Logs `:info` on success, `:warning` on exceptions.
Safe to call multiple times — detaches the old handler first.

# `detach_default_logger`

```elixir
@spec detach_default_logger(atom()) :: :ok | {:error, :not_found}
```

Detaches the default logger.

# `events`

```elixir
@spec events() :: [[atom()]]
```

Returns all telemetry events emitted by this library.

---

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