Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions docs/integrations/databases/sqlalchemy.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,36 @@ 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].

!!! info
To ensure instrumentation captures all emitted events, avoid using `None` value for `engine` keyword argument.

!!! tip
If you use [SQLModel][sqlmodel], you can use the same `SQLAlchemyInstrumentor` to instrument it.

Expand Down
Loading