FastAPI error tracking

FastAPI error tracking built for async

ErrorLens reports unhandled exceptions from FastAPI and Starlette with the request and route, keeps context separate between concurrent async requests, and traces each endpoint's latency.

Set up

pip install errorlens
main.py
import errorlens
from fastapi import FastAPI

errorlens.init(dsn="https://<key>@errorlens.io/<project-id>", traces_sample_rate=0.2)

app = FastAPI()

@app.get("/items/{item_id}")
async def read_item(item_id: int):
    return await fetch_item(item_id)

Built for async Python

  • Context lives in contextvars, so tags and users stay with their own request across awaits
  • Transactions are named after the route template — GET /items/{item_id} — so every item ID groups together
  • httpx calls become spans and carry a traceparent header to the next service
  • Validation errors (4xx) are not reported as errors; server errors are

Privacy

Passwords, tokens, API keys, cookies and card numbers are removed in your app and again on the server before anything is stored — see data scrubbing.

Frequently asked questions

Does it work with Starlette apps without FastAPI?

Yes. The integration hooks Starlette itself, so plain Starlette apps and other frameworks built on it are covered.

How do I trace background work?

Wrap it in errorlens.start_transaction(...) and errorlens.start_span(...), or move it to Celery, whose tasks are traced automatically.

Start tracking errors in minutes

Free hosted plan with 5,000 errors a month, or self-host with no limits. No credit card.