Logfire

Integrate Agno with Logfire to send traces and gain insights into your agent's performance.

Integrating Agno with Logfire

Logfire is Pydantic's observability platform that provides comprehensive tracing and monitoring for AI applications. By integrating Agno with Logfire, you can utilize OpenInference to send traces and gain insights into your agent's performance.

Set OpenAI Key

Set your OPENAI_API_KEY as an environment variable. You can get one from OpenAI.

export OPENAI_API_KEY=sk-***

Prerequisites

  1. Install Dependencies

    Ensure you have the necessary packages installed:

    uv pip install agno openai yfinance opentelemetry-sdk opentelemetry-exporter-otlp openinference-instrumentation-agno
  2. Setup Logfire Account

    • Sign up for an account at Logfire.
    • Obtain your write token from the Logfire dashboard.
  3. Set Environment Variables

    Configure your environment with the Logfire write token:

    export LOGFIRE_WRITE_TOKEN="your-write-token"

Sending Traces to Logfire

Instrument your Agno agent with OpenInference and send traces to Logfire.

import os

from agno.agent import Agent
from agno.models.openai import OpenAIResponses
from agno.tools.yfinance import YFinanceTools
from openinference.instrumentation.agno import AgnoInstrumentor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor

# Set environment variables for Logfire
os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] = "https://logfire-eu.pydantic.dev"  # EU data region
os.environ["OTEL_EXPORTER_OTLP_HEADERS"] = f"Authorization={os.getenv('LOGFIRE_WRITE_TOKEN')}"

# Configure the tracer provider
tracer_provider = TracerProvider()
tracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter()))

# Start instrumenting agno
AgnoInstrumentor().instrument(tracer_provider=tracer_provider)

# Create and configure the agent
agent = Agent(
    name="Stock Price Agent",
    model=OpenAIResponses(id="gpt-5.2"),
    tools=[YFinanceTools()],
    instructions="You are a stock price agent. Answer questions in the style of a stock analyst.",
    debug_mode=True,
)

# Use the agent
agent.print_response("What is the current price of Tesla?")

Notes

  • Environment Variables: Ensure your environment variables are correctly set for the write token and OTLP endpoint.
  • Data Regions: Adjust the OTEL_EXPORTER_OTLP_ENDPOINT for your data region. Available regions include:
    • https://logfire-us.pydantic.dev for the US region
    • https://logfire-eu.pydantic.dev for the EU region
  • Logfire Dashboard: View your traces and monitor performance at Logfire Dashboard

By following these steps, you can effectively integrate Agno with Logfire, enabling comprehensive observability and monitoring of your AI agents.