Integrations
Instrument the libraries you already use (your web framework, database driver, HTTP client, LLM SDK) and their work shows up in Logfire automatically, as spans (one unit of work: a single operation, with a name, a start, and a duration) nested inside the request that triggered them. You don’t add logging by hand; you turn on the integration once and get the traces (the full journey of one request, made of nested spans) for free.
Most integrations are a single logfire.instrument_<package>() call, made once after logfire.configure(). For example, to instrument FastAPI and HTTPX:
from fastapi import FastAPI
import logfire
app = FastAPI()
logfire.configure()
logfire.instrument_fastapi(app)
logfire.instrument_httpx()
# ... your application code here ...
If a package you are using is not listed in this documentation, please let us know on our Slack!
Logfire has documented integrations with many technologies, including:
- LLM Clients and AI Frameworks: Pydantic AI, OpenAI, Anthropic, LangChain, LlamaIndex, Mirascope, LiteLLM, Magentic
- Web Frameworks: FastAPI, Django, Flask, Starlette, AIOHTTP, ASGI, WSGI
- Database Clients: Psycopg, SQLAlchemy, Asyncpg, PyMongo, MySQL, SQLite3, Redis, BigQuery
- HTTP Clients: HTTPX, Requests, AIOHTTP
- Task Queues and Schedulers: Airflow, FastStream, Celery
- Logging Libraries: Standard Library Logging, Loguru, Structlog
- Testing: Pytest
- and more, such as Stripe, AWS Lambda, and system metrics.
The below table lists these integrations and any corresponding logfire.instrument_<package>() calls:
If you are using Logfire with a web application, we also recommend reviewing our Web Frameworks documentation.
Since Logfire is OpenTelemetry compatible, it can be used with any OpenTelemetry instrumentation package. You can find the list of all OpenTelemetry instrumentation packages here.
Many of the integrations documented in the previous section are based upon the OpenTelemetry instrumentation packages with first-class support built into Logfire.
If you are a maintainer of a package and would like to create an integration for Logfire, you can do it!
We’ve created a shim package called logfire-api, which can be used to integrate your package with Logfire.
The idea of logfire-api is that it doesn’t have any dependencies. It’s a very small package that matches the API of Logfire.
We created it so that you can create an integration for Logfire without having to install Logfire itself.
You can use logfire-api as a lightweight dependency of your own package.
If logfire is installed, then logfire-api will use it. If not, it will use a no-op implementation.
This way users of your package can decide whether or not they want to install logfire, and you don’t need to
check whether or not it’s installed.
Here’s how you can use logfire-api:
import logfire_api as logfire
logfire.info('Hello, Logfire!')
All the Logfire API methods are available in logfire-api.