OpenTelemetry Agno Instrumentation

0.58.0 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates how to set up OpenTelemetry to automatically instrument an Agno agent application. It configures a `TracerProvider` with an `OTLPSpanExporter` to send traces to an OpenTelemetry collector and then initializes the `AgnoInstrumentor` before running a simple Agno agent. Ensure your OpenTelemetry collector is running and accessible at the configured OTLP endpoint.

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()

view raw JSON →