SQLAlchemy
The logfire.instrument_sqlalchemy() method will create a span for every query executed by a SQLAlchemy engine.
Install logfire with the sqlalchemy extra:
pip install 'logfire[sqlalchemy]'
uv add 'logfire[sqlalchemy]'
Let’s see a minimal example below. You can run it with python main.py:
from sqlalchemy import create_engine
import logfire
logfire.configure()
engine = create_engine('sqlite:///:memory:')
logfire.instrument_sqlalchemy(engine=engine)
from sqlalchemy import create_engine
import logfire
logfire.configure()
engine_one = create_engine('sqlite:///:memory:')
engine_two = create_engine('sqlite:///:memory:')
logfire.instrument_sqlalchemy(engines=[engine_one, engine_two])
The keyword arguments of logfire.instrument_sqlalchemy() are passed to the SQLAlchemyInstrumentor().instrument() method of the OpenTelemetry SQLAlchemy Instrumentation package, read more about it here.