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

Commit

Permalink
Fix logging context when opening new DB connection (#10141)
Browse files Browse the repository at this point in the history
Fixes #10140
  • Loading branch information
erikjohnston authored Jun 8, 2021
1 parent 9e4610c commit 1092718
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.d/10141.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Report OpenTracing spans for database activity.
12 changes: 9 additions & 3 deletions synapse/storage/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down

0 comments on commit 1092718

Please sign in to comment.