Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 1092718

Browse files
authored
Fix logging context when opening new DB connection (#10141)
Fixes #10140
1 parent 9e4610c commit 1092718

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

changelog.d/10141.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Report OpenTracing spans for database activity.

synapse/storage/database.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,18 @@ def make_pool(
9191
db_args = dict(db_config.config.get("args", {}))
9292
db_args.setdefault("cp_reconnect", True)
9393

94+
def _on_new_connection(conn):
95+
# Ensure we have a logging context so we can correctly track queries,
96+
# etc.
97+
with LoggingContext("db.on_new_connection"):
98+
engine.on_new_connection(
99+
LoggingDatabaseConnection(conn, engine, "on_new_connection")
100+
)
101+
94102
return adbapi.ConnectionPool(
95103
db_config.config["name"],
96104
cp_reactor=reactor,
97-
cp_openfun=lambda conn: engine.on_new_connection(
98-
LoggingDatabaseConnection(conn, engine, "on_new_connection")
99-
),
105+
cp_openfun=_on_new_connection,
100106
**db_args,
101107
)
102108

0 commit comments

Comments
 (0)