HuggingfaceClient.Inference.Telemetry (huggingface_client v0.1.0)

Copy Markdown View Source

Telemetry integration for HuggingfaceClient.

Events emitted

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

EventWhen
[: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

KeyDescription
:providerProvider string, e.g. "groq"
:taskTask string, e.g. "conversational"
:modelModel ID or nil
:statusHTTP status code (:stop only)
:errorException 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.

Returns all telemetry events emitted by this library.

Functions

attach_default_logger(handler_id \\ :huggingface_client_default_logger)

@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(handler_id \\ :huggingface_client_default_logger)

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

Detaches the default logger.

events()

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

Returns all telemetry events emitted by this library.