0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-06-07 05:08:54 +02:00

Fix logging context when opening new DB connection (#10141)

Fixes #10140
This commit is contained in:
Erik Johnston 2021-06-08 13:49:29 +01:00 committed by GitHub
parent 9e4610cc27
commit 1092718cac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View file

@ -0,0 +1 @@
Report OpenTracing spans for database activity.

View file

@ -91,12 +91,18 @@ def make_pool(
db_args = dict(db_config.config.get("args", {}))
db_args.setdefault("cp_reconnect", True)
def _on_new_connection(conn):
# Ensure we have a logging context so we can correctly track queries,
# etc.
with LoggingContext("db.on_new_connection"):
engine.on_new_connection(
LoggingDatabaseConnection(conn, engine, "on_new_connection")
)
return adbapi.ConnectionPool(
db_config.config["name"],
cp_reactor=reactor,
cp_openfun=lambda conn: engine.on_new_connection(
LoggingDatabaseConnection(conn, engine, "on_new_connection")
),
cp_openfun=_on_new_connection,
**db_args,
)