@@ -122,9 +122,11 @@ def reconnect(self) -> None: ...
122122
123123
124124def make_pool (
125+ * ,
125126 reactor : IReactorCore ,
126127 db_config : DatabaseConnectionConfig ,
127128 engine : BaseDatabaseEngine ,
129+ server_name : str ,
128130) -> adbapi .ConnectionPool :
129131 """Get the connection pool for the database."""
130132
@@ -138,7 +140,12 @@ def _on_new_connection(conn: Connection) -> None:
138140 # etc.
139141 with LoggingContext ("db.on_new_connection" ):
140142 engine .on_new_connection (
141- LoggingDatabaseConnection (conn , engine , "on_new_connection" )
143+ LoggingDatabaseConnection (
144+ conn = conn ,
145+ engine = engine ,
146+ default_txn_name = "on_new_connection" ,
147+ server_name = server_name ,
148+ )
142149 )
143150
144151 connection_pool = adbapi .ConnectionPool (
@@ -154,9 +161,11 @@ def _on_new_connection(conn: Connection) -> None:
154161
155162
156163def make_conn (
164+ * ,
157165 db_config : DatabaseConnectionConfig ,
158166 engine : BaseDatabaseEngine ,
159167 default_txn_name : str ,
168+ server_name : str ,
160169) -> "LoggingDatabaseConnection" :
161170 """Make a new connection to the database and return it.
162171
@@ -170,13 +179,18 @@ def make_conn(
170179 if not k .startswith ("cp_" )
171180 }
172181 native_db_conn = engine .module .connect (** db_params )
173- db_conn = LoggingDatabaseConnection (native_db_conn , engine , default_txn_name )
182+ db_conn = LoggingDatabaseConnection (
183+ conn = native_db_conn ,
184+ engine = engine ,
185+ default_txn_name = default_txn_name ,
186+ server_name = server_name ,
187+ )
174188
175189 engine .on_new_connection (db_conn )
176190 return db_conn
177191
178192
179- @attr .s (slots = True , auto_attribs = True )
193+ @attr .s (slots = True , auto_attribs = True , kw_only = True )
180194class LoggingDatabaseConnection :
181195 """A wrapper around a database connection that returns `LoggingTransaction`
182196 as its cursor class.
@@ -187,6 +201,7 @@ class LoggingDatabaseConnection:
187201 conn : Connection
188202 engine : BaseDatabaseEngine
189203 default_txn_name : str
204+ server_name : str
190205
191206 def cursor (
192207 self ,
@@ -200,8 +215,9 @@ def cursor(
200215 txn_name = self .default_txn_name
201216
202217 return LoggingTransaction (
203- self .conn .cursor (),
218+ txn = self .conn .cursor (),
204219 name = txn_name ,
220+ server_name = self .server_name ,
205221 database_engine = self .engine ,
206222 after_callbacks = after_callbacks ,
207223 async_after_callbacks = async_after_callbacks ,
@@ -270,6 +286,7 @@ class LoggingTransaction:
270286 __slots__ = [
271287 "txn" ,
272288 "name" ,
289+ "server_name" ,
273290 "database_engine" ,
274291 "after_callbacks" ,
275292 "async_after_callbacks" ,
@@ -278,15 +295,18 @@ class LoggingTransaction:
278295
279296 def __init__ (
280297 self ,
298+ * ,
281299 txn : Cursor ,
282300 name : str ,
301+ server_name : str ,
283302 database_engine : BaseDatabaseEngine ,
284303 after_callbacks : Optional [List [_CallbackListEntry ]] = None ,
285304 async_after_callbacks : Optional [List [_AsyncCallbackListEntry ]] = None ,
286305 exception_callbacks : Optional [List [_CallbackListEntry ]] = None ,
287306 ):
288307 self .txn = txn
289308 self .name = name
309+ self .server_name = server_name
290310 self .database_engine = database_engine
291311 self .after_callbacks = after_callbacks
292312 self .async_after_callbacks = async_after_callbacks
@@ -571,7 +591,12 @@ def __init__(
571591 self ._clock = hs .get_clock ()
572592 self ._txn_limit = database_config .config .get ("txn_limit" , 0 )
573593 self ._database_config = database_config
574- self ._db_pool = make_pool (hs .get_reactor (), database_config , engine )
594+ self ._db_pool = make_pool (
595+ reactor = hs .get_reactor (),
596+ db_config = database_config ,
597+ engine = engine ,
598+ server_name = self .server_name ,
599+ )
575600
576601 self .updates = BackgroundUpdater (hs , self )
577602 LaterGauge (
@@ -1047,7 +1072,10 @@ def inner_func(conn: _PoolConnection, *args: P.args, **kwargs: P.kwargs) -> R:
10471072 )
10481073
10491074 db_conn = LoggingDatabaseConnection (
1050- conn , self .engine , "runWithConnection"
1075+ conn = conn ,
1076+ engine = self .engine ,
1077+ default_txn_name = "runWithConnection" ,
1078+ server_name = self .server_name ,
10511079 )
10521080 return func (db_conn , * args , ** kwargs )
10531081 finally :
0 commit comments