Logfire
Observability platform from Pydantic — structured logging, tracing, and metrics built on OpenTelemetry. Current version is 4.30.0. Must call logfire.configure() before any instrumentation or spans. Requires LOGFIRE_TOKEN env var for cloud backend. The old pydantic-logfire package is a deprecated stub — use logfire directly. Pricing changed January 2026.
Warnings
- breaking logfire.configure() must be called before any spans, logs, or instrument_*() calls. Omitting it causes all telemetry to be silently dropped — no error is raised.
- breaking instrument_httpx() parameters changed: capture_request_json_body, capture_request_text_body, capture_request_form_data, and capture_response_json_body were removed and replaced by capture_request_body and capture_response_body.
- breaking install_auto_tracing() requires explicit modules parameter — there is no default. Calling it without modules raises TypeError.
- gotcha pydantic-logfire on PyPI is a deprecated stub package that just depends on logfire. Use pip install logfire directly.
- gotcha Logfire pricing changed January 2026. Free Personal plan now limited to 1 seat and 3 projects. Teams exceeding these limits needed to upgrade by February 1, 2026 or be auto-upgraded.
- gotcha Without LOGFIRE_TOKEN, logfire.configure() defaults to local console output only. Cloud export requires the token. Easy to develop locally and forget to set the token in production.
Install
-
pip install logfire -
pip install logfire[fastapi] -
pip install logfire[httpx,requests,sqlalchemy,asyncpg] -
pip install pydantic-logfire
Imports
- logfire.configure
import logfire # Must call configure() FIRST — before any spans or instrumentation # Reads LOGFIRE_TOKEN env var automatically if set logfire.configure() # Then instrument libraries logfire.instrument_fastapi(app) logfire.instrument_httpx() logfire.instrument_sqlalchemy(engine) # Structured logging logfire.info('User {user_id} logged in', user_id=123) # Manual spans with logfire.span('Processing order {order_id}', order_id=order.id): result = process(order)
Quickstart
import logfire
import os
# Set env var: export LOGFIRE_TOKEN='your-token'
# Or pass directly (not recommended for production):
logfire.configure(
token=os.environ.get('LOGFIRE_TOKEN'),
service_name='my-service',
environment='production'
)
# Structured log with attributes
logfire.info('Processing request', user_id=42, endpoint='/api/data')
logfire.warning('Rate limit approaching', limit=100, current=95)
logfire.error('Database error', error_type='ConnectionTimeout', db='postgres')
# Span (traces an operation)
with logfire.span('Fetch user data {user_id}', user_id=42):
# Code here is traced
data = fetch_user(42)
logfire.info('Fetched {record_count} records', record_count=len(data))
# FastAPI integration
from fastapi import FastAPI
app = FastAPI()
logfire.instrument_fastapi(app) # auto-traces all routes