OpenTelemetry Integration

Purpose

The OpenTelemetry Integration subtopic addresses the need for detailed observability into the execution of large language model (LLM) calls and tool invocations within the agent framework. While the parent topic (Telemetry and Observability) covers the overall collection and management of tracing data, this subtopic specifically focuses on registering span processors and instrumenting the tracing of span events related to LLM and tool interactions. This enables developers and operators to monitor, analyze, and debug agent behavior and performance with rich, structured telemetry data.

This integration is essential for understanding the internal workings of agent execution flows, such as when an LLM is called or when a tool function is executed. It supports the broader goal of the telemetry system to provide end-to-end traceability of AI agent operations.

Functionality

Span Processor Registration

Before any telemetry data is generated, span processors must be registered to the local OpenTelemetry tracer provider. This ensures that span data—representing units of work such as LLM calls or tool executions—are processed and exported correctly.

// AddSpanProcessor adds a span processor to the local tracer config.
func AddSpanProcessor(processor sdktrace.SpanProcessor) { ... }

// RegisterTelemetry sets up the local tracer with registered processors.
func RegisterTelemetry() { ... }

Dual Tracer Usage

To accommodate both local and global telemetry configurations, two tracers are used in parallel when starting a trace:

The method StartTrace returns two spans, one from each tracer, allowing simultaneous tracing in both contexts. This dual approach provides flexibility and ensures compatibility with different telemetry setups.

Tracing LLM Calls

The TraceLLMCall function instruments spans with detailed attributes about the LLM request and response:

Tracing Tool Calls

Similarly, tool executions are traced via TraceToolCall and TraceMergedToolCalls functions.

Serialization and Filtering

To avoid exposing sensitive or irrelevant information, the telemetry integration carefully serializes and filters trace data:

This careful handling ensures that telemetry remains useful without compromising data integrity or privacy.

Integration

This subtopic integrates tightly with the parent topic (Telemetry and Observability) by providing the concrete implementation for registering span processors and instrumenting trace spans specifically for LLM and tool calls.

By registering span processors and generating spans with detailed attributes, this subtopic enables a unified telemetry pipeline that feeds observability back into the system for monitoring and diagnostics.

Diagram

sequenceDiagram
participant Agent as Agent
participant Telemetry as OpenTelemetry Integration
participant LLM as LLM Model
participant Tool as Tool Execution
participant SpanProcessor as Span Processor
Agent->>Telemetry: StartTrace(context, "llm_call")
Telemetry->>Telemetry: Create local and global spans
Agent->>LLM: Invoke LLM call
LLM-->>Agent: Return LLM response
Agent->>Telemetry: TraceLLMCall(spans, invocationContext, llmRequest, event)
Telemetry->>SpanProcessor: Set span attributes and end spans
alt Tool call detected
Agent->>Telemetry: StartTrace(context, "tool_call")
Telemetry->>Telemetry: Create spans
Agent->>Tool: Execute tool function
Tool-->>Agent: Return tool response
Agent->>Telemetry: TraceToolCall(spans, tool, args, event)
Telemetry->>SpanProcessor: Set attributes and end spans
end

This sequence diagram visualizes the core process whereby the agent initiates tracing spans for LLM and tool calls, which are then annotated and finalized by the OpenTelemetry span processors registered in this subtopic.