OpenTelemetry Agno Instrumentation
This library provides OpenTelemetry auto-instrumentation for Agno agents, enabling detailed tracing of AI applications. It's part of the OpenInference project, ensuring compatibility with OpenTelemetry collectors and observability backends like Arize Phoenix and Langfuse. Currently at version 0.58.0, it follows a rapid release cadence, with multiple minor and patch releases occurring monthly to incorporate new features and align with evolving OpenTelemetry semantic conventions.
Warnings
- gotcha OpenTelemetry SDK must be initialized before AgnoInstrumentation. If `trace.set_tracer_provider()` is called after `AgnoInstrumentor().instrument()` or after Agno components are imported, no traces will be emitted as API calls will use a no-op implementation.
- breaking The OpenTelemetry semantic conventions, particularly for Generative AI (GenAI), are actively evolving. Recent versions of `opentelemetry-instrumentation-agno` frequently update to align with new OpenTelemetry GenAI semantic conventions (e.g., changes to `gen_ai.tool.name`). This can lead to breaking changes in attribute names or structures if your observability backend or custom analysis tools rely on older semantic conventions.
- gotcha This instrumentation library only works if the `agno` package is installed alongside it. Without `agno` present, the instrumentation will not find the target library to patch, and no Agno-specific traces will be generated.
Install
-
pip install opentelemetry-instrumentation-agno agno opentelemetry-sdk opentelemetry-exporter-otlp-proto-http
Imports
- AgnoInstrumentor
from openinference.instrumentation.agno import AgnoInstrumentor
Quickstart
import os
from opentelemetry import trace
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from openinference.instrumentation.agno import AgnoInstrumentor
# Agno related imports for the example
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.duckduckgo import DuckDuckGoTools
# Configure OpenTelemetry TracerProvider
resource = Resource.create({"service.name": "agno-agent-app"})
provider = TracerProvider(resource=resource)
# Export spans to an OTLP collector (e.g., SigNoz, Jaeger, Arize Phoenix)
# Replace with your actual OTLP endpoint if not using default localhost
otlp_endpoint = os.environ.get("OTEL_EXPORTER_OTLP_ENDPOINT", "http://localhost:4318/v1/traces")
span_processor = SimpleSpanProcessor(OTLPSpanExporter(endpoint=otlp_endpoint))
provider.add_span_processor(span_processor)
# Set the global TracerProvider
trace.set_tracer_provider(provider)
# Initialize Agno instrumentation
AgnoInstrumentor().instrument()
# Example Agno Agent application
print("Agno Agent started...")
agent = Agent(
model=OpenAIChat(id=os.environ.get("OPENAI_MODEL_ID", "gpt-4o-mini")),
tools=[DuckDuckGoTools()],
markdown=True,
debug_mode=True,
)
response = agent.print_response("What is the current weather in London?")
print(f"Agent Response: {response}")
print("Agno Agent finished. Check your OTLP collector for traces.")
# In a real application, you might want to ensure all spans are exported
# before the application exits. For this simple example, we rely on
# the SimpleSpanProcessor flushing on shutdown. For production, consider BatchSpanProcessor.
provider.shutdown()