---
title: Python Observability with OpenTelemetry | Pydantic Logfire
description: >-
  Instrument any Python app with OpenTelemetry and Pydantic Logfire. Auto-trace
  FastAPI, Django, SQLAlchemy, and httpx in two lines, then query it with SQL.
canonical: 'https://pydantic.dev/logfire/python'
---

> Markdown version of [Trace, monitor and debug your Python app](https://pydantic.dev/logfire/python) — the canonical HTML page.
>
> Site index: [/llms.txt](https://pydantic.dev/llms.txt)

---

# Trace, monitor and debug your Python app

Logfire for Python

Python Observability from the team behind Pydantic: one line instruments FastAPI, Django, SQLAlchemy or httpx, and everything is queryable in plain SQL. Standard OpenTelemetry, no lock-in.

[Try Logfire for free](https://logfire.pydantic.dev/login?intent=signup) [See the Python docs](https://pydantic.dev/docs/logfire/instrument/python/)

Set up Logfire with your coding agent:

uvx logfire-cli wizard

Install the SDK

```bash
pip install \
  'logfire[fastapi,sqlalchemy,httpx]'
logfire auth  # or set LOGFIRE_TOKEN
```

Instrument your app

```python
import logfire

logfire.configure()

# one call per library you use
logfire.instrument_fastapi(app)
logfire.instrument_httpx()
logfire.instrument_sqlalchemy(
    engine=engine)
```

Full details are in the [Python setup guide](https://pydantic.dev/docs/logfire/instrument/python/).

Trusted by teams building production software and AI

**Customers:** Motorola, Sophos, Airbyte, Pictet, Vox Media, Weaviate, Amboss, Tiger Data

What you get

## One request, one trace

![A Logfire trace of a Python batch worker: the manual process-inbox span, Pydantic validation of each record, the Postgres query and outbound HTTP call per order, and a rejected record whose validation failed](https://pydantic.dev/assets/logfire/language-traces/python-trace.png)

Every request through your Python app becomes a trace: the full timeline of that request, built from nested spans. Each span is one timed unit of work — a database query, an outbound call, a Pydantic validation — with its timing, attributes, and errors attached.

Try it on your stack

## See your own Python trace

Start free with 10 million spans, logs, and metrics each month. No credit card required.

[Start free](https://logfire.pydantic.dev/login?intent=signup) [Read the Python setup guide](https://pydantic.dev/docs/logfire/instrument/python/)

How it works

## Instrument the edges, see the whole request

### Auto-instrument your whole stack

The high-value telemetry comes from the libraries you already use. Each integration is one line: logfire.instrument\_fastapi(app), logfire.instrument\_django(), logfire.instrument\_sqlalchemy(engine=engine), logfire.instrument\_psycopg(), logfire.instrument\_httpx(). Every request opens a trace, and every query and outbound call inside it becomes a timed child span. You add instrumentation at the edges and let the request carry the context.

### Trace your own logic

For the code that is actually yours, open a span where a business operation begins with logfire.span("process\_order", order\_id=order\_id), or decorate a function with @logfire.instrument(). Attributes like order\_id are queryable, so "every order over $500 that took longer than two seconds" is a real question you can ask.

### It understands Pydantic

Most of the Python world validates data with Pydantic, and Logfire is built by the same team. Call logfire.instrument\_pydantic() and validation runs show up as spans, with the model, the inputs, and any validation errors captured. When a request fails because a payload did not match your schema, you see exactly which field and why, in production.

### Traces, metrics, and logs in one place

Send your own metrics and structured logs alongside spans, all in the same project and queryable with the same SQL. Add the system-metrics extra and call logfire.instrument\_system\_metrics(base='full') to capture CPython runtime metrics, including GC collections, thread count, context switches, and memory.

### OpenTelemetry-native, no lock-in

Because Logfire speaks OpenTelemetry natively, you are never trapped. Standard opentelemetry-instrument usage and manual OTel spans work unchanged, and you can send the same data to another backend or self-host without touching your instrumentation. Your instrumentation is an asset you own, not rented from a vendor.

Coverage

## One line each, for the Python libraries you already use

* [FastAPI](https://pydantic.dev/docs/logfire/integrations/web-frameworks/fastapi/)
* [Django](https://pydantic.dev/docs/logfire/integrations/web-frameworks/django/)
* [Flask](https://pydantic.dev/docs/logfire/integrations/web-frameworks/flask/)
* [Starlette](https://pydantic.dev/docs/logfire/integrations/web-frameworks/starlette/)
* [SQLAlchemy](https://pydantic.dev/docs/logfire/integrations/databases/sqlalchemy/)
* [Psycopg](https://pydantic.dev/docs/logfire/integrations/databases/psycopg/)
* [asyncpg](https://pydantic.dev/docs/logfire/integrations/databases/asyncpg/)
* [Redis](https://pydantic.dev/docs/logfire/integrations/databases/redis/)
* [PyMongo](https://pydantic.dev/docs/logfire/integrations/databases/pymongo/)
* [HTTPX](https://pydantic.dev/docs/logfire/integrations/http-clients/httpx/)
* [Requests](https://pydantic.dev/docs/logfire/integrations/http-clients/requests/)
* [aiohttp](https://pydantic.dev/docs/logfire/integrations/http-clients/aiohttp/)
* [Celery](https://pydantic.dev/docs/logfire/integrations/event-streams/celery/)
* [Airflow](https://pydantic.dev/docs/logfire/integrations/event-streams/airflow/)
* [Pydantic AI](https://pydantic.dev/docs/logfire/integrations/llms/pydanticai/)
* [OpenAI](https://pydantic.dev/docs/logfire/integrations/llms/openai/)
* [Anthropic](https://pydantic.dev/docs/logfire/integrations/llms/anthropic/)
* [LangChain](https://pydantic.dev/docs/logfire/integrations/llms/langchain/)

Each one is a single `logfire.instrument_*()` call, and each links to its setup guide. The full list is in the [integrations documentation](https://pydantic.dev/docs/logfire/integrations/).

Query

## Query your Python telemetry with SQL

If you can ask it, SQL can find out

* Query your traces, metrics and logs with real SQL
* No proprietary query language to learn
* AI models are great at writing SQL
* From a one-off investigation to an alert, dashboard, or SLO

```sql
select
  attributes->>'http.route' as route,
  count(*) as requests,
  avg(duration) as avg_seconds
from records
where duration > 1
group by route
order by avg_seconds desc;
```

Try it on your stack

## See Logfire on your own telemetry

Start free with 10 million spans, logs, and metrics each month. No credit card required.

[Start free](https://logfire.pydantic.dev/login?intent=signup) [Read the setup guide](https://pydantic.dev/docs/logfire/get-started/)

Proof

## In production

> We are finding and fixing issues in five minutes instead of an hour, which is obviously increasing uptime for our clients.

Zach Silver, Staff Software Engineer, BoostedAI [Read the case study](https://pydantic.dev/case-studies/boostedai)

Decision guide

## Is Logfire right for your Python app?

### Choose Logfire if

* You want observability for a Python app without wiring up a backend yourself
* You want auto-instrumentation for FastAPI, Django, SQLAlchemy, httpx, and more in one line each
* You want to query traces, metrics, and logs with PostgreSQL-compatible SQL
* You want validation and Pydantic models visible in your traces
* You want the portability of OpenTelemetry with a product that feels like Python

### Choose a traditional APM if

* You are already deeply integrated with a specific APM vendor's ecosystem
* You need a vendor-only integration or compliance capability Logfire does not offer
* You want one vendor's agent and dashboards, and are comfortable with their pricing model

FAQ

## Common questions

### How do I add OpenTelemetry to a Python application?

Install an OpenTelemetry-compatible SDK and instrument your libraries. With Pydantic Logfire it is pip install with the extras for the integrations you use, for example pip install 'logfire\[fastapi,sqlalchemy]', then logfire.configure(), then one line per library such as logfire.instrument\_fastapi(app). Logfire is OpenTelemetry-native, so standard opentelemetry-instrument usage and manual OTel spans also work unchanged.

### What is the difference between logging and observability in Python?

Logs are individual events. Observability connects them: a trace ties a request to every database query, external call, and function it triggered, with timing and attributes. That is what lets you see why a specific request was slow, rather than scrolling through disconnected log lines.

### Does OpenTelemetry instrumentation slow down my Python app?

Auto-instrumentation is designed for production and adds minimal overhead. Telemetry is batched and exported asynchronously, and you can sample traces to control volume. The visibility you gain into slow queries and failing calls typically pays for the small cost many times over.

### Is Pydantic Logfire locked to a proprietary format?

No. Logfire is built on OpenTelemetry, the open industry standard. Your instrumentation is portable: you can export the same data to another OTel-compatible backend, and the SDK works with standard OpenTelemetry tooling. Logfire adds Python-first ergonomics and SQL querying on top of the open standard.

### Can I query my Python traces directly?

Yes. Logfire lets you query your traces, metrics, and logs with SQL. Any question you can express in SQL becomes a dashboard, an alert, or an ad-hoc investigation, with no proprietary query language to learn.

Keep reading

## If you are still comparing

* [FastAPI The same instrumentation on a FastAPI app, including the request lifecycle and dependency spans you get for free. Read](https://pydantic.dev/logfire/fastapi)
* [Django Views, ORM queries and templates on one timeline, with the N+1 queries visible rather than inferred. Read](https://pydantic.dev/logfire/django)
* [Logfire vs Datadog Compare Python instrumentation, OpenTelemetry support, retention, and pricing with Datadog. Read](https://pydantic.dev/logfire/vs-datadog)
* [Pricing On the Personal plan, 10 million records a month are free; ingestion pauses at the cap instead of billing for overage. Read](https://pydantic.dev/pricing)

## Start seeing your Python app

Get started with 10 million free spans, logs, and metrics per month. No credit card required.

* [Start free](https://logfire.pydantic.dev/login?intent=signup)
* [Book a demo](https://pydantic.dev/contact)
* [View pricing plans](https://pydantic.dev/pricing)
