SQLAlchemy¶
The logfire.instrument_sqlalchemy() method creates a span for each query executed by the SQLAlchemy engine.
install¶
Install logfire using sqlalchemy extra:
{{ install_logfire(extras=['SQLalchemy']) }}
usage¶
Let's look at a minimal example below. You can run it using python main.py:
main.py
import logfire
from sqlalchemy import create_engine
logfire.configure()
engine = create_engine("sqlite:///:memory:")
logfire.instrument_sqlalchemy(engine=engine)
logfire.instrument_sqlalchemy() Keyword parameters are passed to OpenTelemetry SQLInstrumentation package SQLAlchemyInstrumentor().instrument() Methods,replace this text with Read more about it.
Hint
If you use SQLModel, you can use the same SQLAlchemyInstrumentor to detect it.
本文总阅读量次