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 (:stopand:exceptiononly):monotonic_time— start time (:startonly)
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
)
Summary
Functions
Attaches a default structured logger handler.
Detaches the default logger.
Returns all telemetry events emitted by this library.
Functions
@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.
@spec detach_default_logger(atom()) :: :ok | {:error, :not_found}
Detaches the default logger.
@spec events() :: [[atom()]]
Returns all telemetry events emitted by this library.