name: logfire-4-32-1 description: AI observability platform built on OpenTelemetry by the Pydantic team. Native SDKs for Python, JavaScript/TypeScript, and Rust. Use when instrumenting applications with distributed tracing, metrics, and logs; configuring auto-instrumentation for FastAPI, OpenAI, LangChain, and databases; querying trace data via SQL; or integrating with the Logfire cloud platform.
Pydantic Logfire 4.32.1
Overview
From the team behind Pydantic Validation, Pydantic Logfire is an observability platform built on OpenTelemetry with native SDKs for Python, JavaScript/TypeScript, and Rust — plus support for any language via standard OpenTelemetry exporters. It unifies traces, metrics, and structured logs into a single platform with SQL-based querying powered by Apache DataFusion.
Logfire is AI-native: it provides purpose-built features for LLM applications including conversation panels, token tracking, cost monitoring, tool call inspection, streaming support, and multi-turn conversation tracing. Unlike AI-only observability tools, Logfire traces your entire application stack so you can debug whether a problem is in the AI layer or the backend.
Key differentiators:
- SQL-based analysis — query all observability data using PostgreSQL-compatible SQL
- MCP server — LLMs can directly query production telemetry via the Model Context Protocol
- Deep Python integration — rich display of Python objects, event-loop telemetry, profiling, auto-tracing
- Pydantic integration — automatic validation analytics and structured model display
- No lock-in — built on OpenTelemetry; data export to any OTel-compatible backend
When to Use
- Instrumenting Python, JavaScript/TypeScript, or Rust applications with distributed tracing
- Adding auto-tracing to web frameworks (FastAPI, Django, Flask, Starlette, AIOHTTP)
- Monitoring LLM/AI application calls (OpenAI, Anthropic, LangChain, LlamaIndex, Pydantic AI)
- Setting up metrics collection (counters, histograms, gauges, callbacks)
- Querying observability data with SQL or via the MCP server
- Configuring sampling strategies (head, tail, combined)
- Scrubbing sensitive data from logs and spans
- Deploying self-hosted Logfire on Kubernetes
- Integrating alternative OTel clients (Go, Java, .NET, etc.)
Core Concepts
Logfire is built on four key observability concepts:
Span — The atomic unit of telemetry data. A span has a start and end time (thus a duration), can carry structured attributes, and nests within other spans. Think of spans as logs with extra functionality.
Trace — A tree structure of spans showing the path of any request through your application. Spans are ordered and nested, like a stack trace showing all services touched.
Metric — Calculated values collected at regular intervals (request latency, CPU load, queue length). Aggregated over time for charting trends, SLOs, and alerts.
Log — A timestamped text record with no duration. Structured logs (recommended) carry attributes as JSON.
Installation / Setup
Python
logfire auth # authenticate (stores credentials in ~/.logfire/default.toml)
logfire projects use <project-name> # select project
import logfire
logfire.configure() # initialize once before logging
logfire.info('Hello, {name}!', name='world')
JavaScript/TypeScript
import * as logfire from '@pydantic/logfire-node'
logfire.configure({
token: 'your-write-token',
serviceName: 'my-service',
})
logfire.info('Hello from Node.js', { key: 'value' }, { tags: ['example'] })
Rust
Use the logfire crate from crates.io. Configuration follows standard OTel patterns with Logfire-specific defaults.
CLI Commands
logfire auth— authenticate with browser loginlogfire clean [--logs]— clean generated fileslogfire inspect— identify missing OTel instrumentation packageslogfire projects list— list accessible projectslogfire projects use <name>— select active projectlogfire projects new <name>— create a new projectlogfire --region eu author--region us auth— specify data region
Advanced Topics
Concepts Deep Dive: Spans, traces, metrics, logs with examples → Concepts
Manual Tracing: Spans, attributes, messages, f-strings, exceptions, log levels → Manual Tracing
Auto-Tracing: Automatic function-level tracing with module filtering and duration thresholds → Auto-Tracing
Integrations: Web frameworks, databases, HTTP clients, LLMs, task queues, logging libraries → Integrations
AI Observability: LLM panels, token tracking, cost monitoring, tool call inspection, evaluations → AI Observability
Metrics: Counters, histograms, up-down counters, gauges, callback metrics → Metrics
Configuration: Programmatic, environment variables, pyproject.toml, multiple configs → Configuration
Sampling: Head sampling, tail sampling by level/duration, combined strategies → Sampling
Distributed Tracing: Context propagation, thread/pool executors, cross-service traces → Distributed Tracing
SQL Querying: Records table schema, columns, JSON operators, time bucketing → SQL Reference
Scrubbing: Sensitive data redaction, custom patterns, callbacks, security tips → Scrubbing
Alternative Backends: Jaeger, OTel Collector, environment variable configuration → Alternative Backends
JavaScript SDK: Browser, Next.js, Cloudflare Workers, Express, Node.js, Deno → JavaScript SDK
MCP Server: Remote MCP for LLM access to telemetry data → MCP Server
Self-Hosted: Kubernetes deployment, Helm chart, system requirements → Self-Hosted