LLMTracingAdapter
Base adapter for tracing LLM provider API interactions using OpenTelemetry.
This abstract class provides the foundation for implementing provider-specific tracing adapters. It handles HTTP request/response interception, attribute extraction, error handling, and streaming support. Subclasses implement provider-specific parsing logic for different API formats (OpenAI, Anthropic, Gemini, etc.).
Usage
Extend this class to create a provider-specific adapter:
class AnthropicLLMTracingAdapter : LLMTracingAdapter(GenAiSystemIncubatingValues.ANTHROPIC) {
override fun getRequestBodyAttributes(span: Span, request: Request) {
// Parse Anthropic-specific request format
}
override fun getResponseBodyAttributes(span: Span, response: Response) {
// Parse Anthropic-specific response format
}
override fun getSpanName(request: Request) = "Anthropic-generation"
override fun isStreamingRequest(request: Request) = false
override fun handleStreaming(span: Span, url: Url, events: String) = Unit
}Content copied to clipboard
Use with the instrument() function:
val client = instrument(HttpClient(), AnthropicLLMTracingAdapter())Content copied to clipboard
Parameters
genAISystem
The name of the GenAI system (e.g., "openai", "anthropic", "gemini")