diff --git a/docs/integrations/databases/sqlalchemy.md b/docs/integrations/databases/sqlalchemy.md index 855bff744..5f4d85767 100644 --- a/docs/integrations/databases/sqlalchemy.md +++ b/docs/integrations/databases/sqlalchemy.md @@ -14,18 +14,37 @@ Install `logfire` with the `sqlalchemy` extra: Let's see a minimal example below. You can run it with `python main.py`: -```py title="main.py" -import logfire -from sqlalchemy import create_engine +=== "Instrument a Single Engine" -logfire.configure() + ```py title="main.py" + import logfire + from sqlalchemy import create_engine -engine = create_engine("sqlite:///:memory:") -logfire.instrument_sqlalchemy(engine=engine) -``` + logfire.configure() + + engine = create_engine("sqlite:///:memory:") + logfire.instrument_sqlalchemy(engine=engine) + ``` + +=== "Instrument Multiple Engines" + + ```py title="main.py" + import logfire + from sqlalchemy import create_engine + + 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][opentelemetry-sqlalchemy]. +!!! warning + It's best to use the `engine` or `engines` arguments. If no engine is specified, then `instrument_sqlalchemy` may + only work if it's called before `sqlalchemy` is imported, in which case all engines are instrumented. + !!! tip If you use [SQLModel][sqlmodel], you can use the same `SQLAlchemyInstrumentor` to instrument it.