ExLLM.Infrastructure.Telemetry (ex_llm v0.8.1)
View SourceTelemetry instrumentation for ExLLM.
This module provides telemetry event definitions and helpers for instrumenting
ExLLM operations. It follows the standard :telemetry
conventions and can be
integrated with various observability backends.
Event Structure
All events follow the pattern: [:ex_llm, :component, :operation, :phase]
Where phase is one of: :start
, :stop
, :exception
Integration Options
- Logging: Attach handlers to log events
- Metrics: Use
ExLLM.Infrastructure.Telemetry.Metrics
withtelemetry_metrics
- Tracing: Use
ExLLM.Infrastructure.Telemetry.OpenTelemetry
for distributed tracing
Example
# Attach a simple logger
:telemetry.attach(
"log-llm-requests",
[:ex_llm, :chat, :stop],
&MyApp.handle_event/4,
nil
)
Summary
Functions
Attach a basic logger handler for debugging.
Detach the default logger.
Helper to emit cache events.
Helper to emit cost events.
Helper for streaming events.
Returns all telemetry event names.
Execute a function and emit telemetry events.
Functions
Attach a basic logger handler for debugging.
This is useful during development to see all telemetry events.
Detach the default logger.
Helper to emit cache events.
Helper to emit cost events.
Helper for streaming events.
Returns all telemetry event names.
Execute a function and emit telemetry events.
This is the core instrumentation helper that emits start/stop/exception events and measures duration automatically.
Options
:telemetry_metadata
- Additional metadata to include in events:telemetry_options
- Options like sampling rate
Example
span([:ex_llm, :chat], %{model: "gpt-4"}, fn ->
# Your code here
{:ok, result}
end)