Tracing Storage
Persist traces to SQLite or PostgreSQL for production-grade observability
Tracing storage persists traces beyond program execution, enabling historical analysis, cost reporting, and production monitoring.
Storage Options
Peargent provides five storage backends for traces:
In-Memory (Default)
Best for: Development and testing. Zero setup, but data is lost on exit.
from peargent.observability import enable_tracing
tracer = enable_tracing() File-Based Storage
Best for: Small-scale apps and debugging. Simple JSON files.
from peargent.storage import File
tracer = enable_tracing(store_type=File(storage_dir="./traces")) SQLite Storage
Best for: Local production. Single-file database, fast queries.
from peargent.storage import Sqlite
tracer = enable_tracing(store_type=Sqlite(connection_string="sqlite:///./traces.db")) PostgreSQL Storage
Best for: Multi-server production. Scalable and powerful.
from peargent.storage import Postgresql
tracer = enable_tracing(
store_type=Postgresql(connection_string="postgresql://user:pass@localhost/dbname")
)Redis Storage
Best for: High-speed caching and distributed systems.
from peargent.storage import Redis
tracer = enable_tracing(
store_type=Redis(host="localhost", port=6379, key_prefix="my_app")
)Storage Comparison
| Feature | In-Memory | File | SQLite | PostgreSQL | Redis |
|---|---|---|---|---|---|
| Persistence | ❌ | ✅ | ✅ | ✅ | ⚠️ Optional |
| Query Performance | Fastest | Slow | Fast | Fast | Fastest |
| Concurrent Access | ❌ | ❌ | ⚠️ Limited | ✅ Excellent | ✅ Excellent |
| Production Ready | ❌ | ❌ | ⚠️ Single-server | ✅ Yes | ✅ Yes |
| Setup Required | ❌ None | ❌ None | ❌ None | ✅ Server needed | ✅ Server needed |
Custom Table Names
You can customize table names to avoid conflicts with your existing schema.
SQLite & PostgreSQL
Use table_prefix to namespace your tables (creates {prefix}_traces and {prefix}_spans).
tracer = enable_tracing(
store_type=Sqlite(
connection_string="sqlite:///./traces.db",
table_prefix="my_app"
)
)Redis
Use key_prefix to namespace your Redis keys (creates {prefix}:traces:*).
tracer = enable_tracing(
store_type=Redis(
host="localhost",
port=6379,
key_prefix="my_app"
)
)What's Next?
Session and User Context Learn how to tag traces with user and session IDs for better organization and analysis.