Session Tracer

The SessionTracer provides comprehensive tracing capabilities for AI applications, allowing you to track interactions, monitor performance, and debug issues.

Overview

The tracing system captures:
  • LM Interactions: All language model requests and responses
  • Runtime Events: System events and state changes
  • Performance Metrics: Timing and resource usage
  • Error Tracking: Exceptions and failure modes

Basic Usage

from synth_ai.tracing_v3.session_tracer import SessionTracer

# Initialize tracer
tracer = SessionTracer()

# Start a session
tracer.start_session("my-session-id")

# Your AI application code here...

# End session (automatically saves)
tracer.end_session()

Generated Documentation

Detailed API documentation is available for:

Integration with LM

The SessionTracer automatically integrates with the LM system:
from synth_ai.lm.core.main_v3 import LM
from synth_ai.tracing_v3.session_tracer import SessionTracer

# Create tracer and LM
tracer = SessionTracer()
lm = LM(model_name="gpt-4o-mini", session_tracer=tracer)

# Start tracing
tracer.start_session("chat-session")

# All LM calls are automatically traced
response = lm.respond("Hello!")

tracer.end_session()

Storage Backends

The tracer supports multiple storage backends:
  • SQLite: Local file-based storage
  • Turso: Distributed SQLite with sync
  • PostgreSQL: Enterprise database support
  • Memory: In-memory storage for testing
# Configure storage backend
tracer = SessionTracer(
    storage_config={
        "type": "turso",
        "database_url": "libsql://your-db.turso.io",
        "auth_token": "your-token"
    }
)

Event Types

The system captures different types of events:

LM Events

  • Request details (model, messages, parameters)
  • Response content and metadata
  • Timing information
  • Token usage and costs

Runtime Events

  • Function calls and returns
  • State changes
  • Error conditions
  • Custom application events