Sycophant.Telemetry (sycophant v0.4.2)

Copy Markdown

Telemetry events for observability and metrics.

Sycophant emits :telemetry events at key points in the request lifecycle, following the standard span pattern.

Request Events

  • [:sycophant, :request, :start] - Request begins. Measurements: %{system_time: integer}. Metadata: %{model, provider, wire_protocol, has_tools?, has_stream?}.

  • [:sycophant, :request, :stop] - Request succeeds. Measurements: %{duration: integer} (native time units). Metadata: start metadata merged with %{duration, usage, response_model, response_id, finish_reason}. Usage includes token counts, cache token counts, and cost fields (from LLMDB pricing).

  • [:sycophant, :request, :error] - Request fails. Measurements: %{duration: integer} (native time units). Metadata: start metadata merged with %{error, error_class}.

Streaming Events

  • [:sycophant, :stream, :chunk] - Individual stream chunk received. Measurements: %{}. Metadata: %{chunk_type: atom}.

Embedding Events

  • [:sycophant, :embedding, :start] - Embedding request begins.
  • [:sycophant, :embedding, :stop] - Embedding request succeeds.
  • [:sycophant, :embedding, :error] - Embedding request fails.

Attaching Handlers

:telemetry.attach_many("sycophant-logger", Sycophant.Telemetry.events(), &handle_event/4, nil)

Summary

Functions

Returns the list of telemetry event names emitted by Sycophant.

Wraps a function in start/stop/error telemetry events.

Emits a telemetry event for a single stream chunk.

Functions

events()

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

Returns the list of telemetry event names emitted by Sycophant.

span(metadata, fun)

@spec span(map(), (-> {:ok, term()} | {:error, term()})) ::
  {:ok, term()} | {:error, term()}

Wraps a function in start/stop/error telemetry events.

stream_chunk(chunk)

@spec stream_chunk(Sycophant.StreamChunk.t()) :: :ok

Emits a telemetry event for a single stream chunk.