🔥 LogFire Integration
🔥

LogFire

Pydantic Team's Observability Platform - Native tracing, logging, and metrics for your Pydantic AI agents. Built by the makers of Pydantic!

Native Pydantic AI Support
Zero-Configuration
Token & Cost Tracking
OpenTelemetry Compatible

🎯 Why LogFire for Pydantic AI?

LogFire is built by the Pydantic team specifically for Python applications, with native Pydantic AI integration

Trace Agent Executions

Full visibility into LLM calls

Monitor Tool Usage

MCP tools and regular tools

Track Token & Costs

Automatic cost calculation

View Conversations

Rich formatting for history

Analyze Performance

Latency, success rates

Debug Issues

Detailed span information

The integration is opt-in and works gracefully when LogFire is not configured!

📦 Installation

Basic Installation

# Install Pydantic AI support
uv tool install superoptix --with "superoptix[frameworks-pydantic-ai]"

# Install LogFire observability (separate, optional)
uv tool install superoptix --with "superoptix[logfire]"

# Or install both together
uv tool install superoptix --with "superoptix[frameworks-pydantic-ai,logfire]"

Important: LogFire is NOT included in superoptix[all] due to OpenTelemetry version conflicts with google-adk. Install LogFire separately!

Safe Combinations:

  • superoptix[frameworks-pydantic-ai,logfire] - Works!
  • superoptix[frameworks-openai,logfire] - Works!
  • superoptix[all] - Works! (LogFire not included)
  • superoptix[all,logfire] - Fails! (google-adk conflict)

⚙️ Configuration

Playbook Configuration

apiVersion: agent/v1
kind: AgentSpec
metadata:
  name: Developer Assistant
  version: "1.0.0"
  
spec:
  # LogFire configuration - place it here in the spec section
  logfire:
    enabled: true  # Default: true (auto-detects if LogFire is available)
  
  # Other spec configurations (same level)
  language_model:
    provider: ollama
    model: llama3.1:8b
    api_base: http://localhost:11434
  
  persona:
    role: Software Developer
    goal: Write clean code

Cloud Dashboard Setup

# 1. Authenticate with LogFire (one-time setup)
logfire auth

# 2. LogFire auto-configures after auth
# No additional code needed!

# 3. Run your agent
super agent run developer --goal "Your task"

# 4. View traces at https://logfire.pydantic.dev

After authenticating, traces are automatically sent to LogFire Cloud!

📋 What Gets Traced

Agent Execution

  • Agent initialization
  • Input processing
  • Output generation
  • Execution duration

LLM Interactions

  • Model calls (request/response)
  • Full conversation history
  • Token usage
  • Cost calculations

Tool Usage

  • MCP tool invocations
  • Tool parameters and results
  • Tool execution time
  • Success/failure status

Structured Output

  • Validation events
  • Field extraction
  • Output formatting
  • Pydantic model validation

Errors

  • Exception traces
  • Error messages
  • Stack traces
  • Context information

Performance

  • Latency metrics
  • Throughput
  • Success rates
  • Resource usage

🚀 Quick Start

Complete Workflow

# 1. Initialize project
super init my_project
cd my_project

# 2. Pull agent
super agent pull developer

# 3. Enable LogFire in playbook (edit playbook YAML)
#    Add to spec section:
#    spec:
#      logfire:
#        enabled: true

# 4. Authenticate with LogFire (one-time setup)
logfire auth

# 5. Compile with Pydantic AI
super agent compile developer --framework pydantic-ai

# 6. Run agent (LogFire traces captured automatically)
super agent run developer --goal "Implement a REST API endpoint"

# 7. View traces at https://logfire.pydantic.dev

🔍 Troubleshooting

Traces Not Appearing

Solution: Verify LogFire is authenticated: logfire auth. Check if LogFire is configured before agent initialization.

ImportError: No module named 'logfire'

Solution: uv tool install superoptix --with "superoptix[frameworks-pydantic-ai,logfire]"

Instrumentation Not Working

Solution: Ensure LogFire is configured BEFORE agent initialization. Re-compile agent: super agent compile developer --framework pydantic-ai

Graceful Fallback

If LogFire is not installed or not configured, the integration silently skips instrumentation. Your agent will work normally without errors. This is intentional - LogFire is optional!

🔥 Ready for Pydantic AI Observability?

Start using LogFire with SuperOptiX for native Pydantic AI tracing!