ExLLM.Infrastructure.Telemetry.Instrumentation (ex_llm v0.8.1)
View SourceHelper module for adding telemetry instrumentation to ExLLM operations.
This module provides macros and functions to easily add telemetry to existing code with minimal changes. It follows the patterns established in the centralized telemetry module.
Usage
Basic Instrumentation
defmodule MyModule do
import ExLLM.Infrastructure.Telemetry.Instrumentation
def my_function(args) do
instrument [:ex_llm, :my_module, :my_function], %{args: args} do
# Your code here
{:ok, result}
end
end
end
Provider Instrumentation
defmodule MyAdapter do
import ExLLM.Infrastructure.Telemetry.Instrumentation
def call(model, messages, opts) do
instrument_provider :my_provider, model, opts do
# API call here
{:ok, response}
end
end
end
HTTP Instrumentation
def post_json(url, body, headers, opts) do
instrument_http :post, url do
HTTPClient.post(url, body, headers)
end
end
Summary
Functions
Helper to check if a cost threshold has been exceeded.
Helper to extract usage information from various response formats.
Instrument a block of code with telemetry events.
Instrument cache operations.
Instrument cache store operations.
Instrument context truncation.
Instrument HTTP requests with standard metadata.
Instrument a provider API call with standard metadata.
Instrument session operations.
Instrument streaming operations.
Functions
Helper to check if a cost threshold has been exceeded.
Helper to extract usage information from various response formats.
Instrument a block of code with telemetry events.
Automatically emits start/stop/exception events and measures duration.
Instrument cache operations.
Instrument cache store operations.
Instrument context truncation.
Instrument HTTP requests with standard metadata.
Instrument a provider API call with standard metadata.
Instrument session operations.
Instrument streaming operations.