@@ -195,6 +195,8 @@ def instrument_connection(
195195 enable_commenter : bool = False ,
196196 commenter_options : dict = None ,
197197 connect_module : typing .Callable [..., typing .Any ] = None ,
198+ db_api_integration_factory : typing .ClassVar = None ,
199+ get_cnx_proxy : typing .Callable [..., typing .Any ] = None ,
198200):
199201 """Enable instrumentation in a database connection.
200202
@@ -210,6 +212,10 @@ def instrument_connection(
210212 enable_commenter: Flag to enable/disable sqlcommenter.
211213 commenter_options: Configurations for tags to be appended at the sql query.
212214 connect_module: Module name where connect method is available.
215+ db_api_integration_factory: The `DatabaseApiIntegration` to use. If none is passed the
216+ default one is used.
217+ get_cnx_proxy: Method to get traced connextion proxy. If none is passed the
218+ default one is used.
213219
214220 Returns:
215221 An instrumented connection.
@@ -218,7 +224,11 @@ def instrument_connection(
218224 _logger .warning ("Connection already instrumented" )
219225 return connection
220226
221- db_integration = DatabaseApiIntegration (
227+ db_api_integration_factory = (
228+ db_api_integration_factory or DatabaseApiIntegration
229+ )
230+
231+ db_integration = db_api_integration_factory (
222232 name ,
223233 database_system ,
224234 connection_attributes = connection_attributes ,
@@ -230,7 +240,9 @@ def instrument_connection(
230240 connect_module = connect_module ,
231241 )
232242 db_integration .get_connection_attributes (connection )
233- return get_traced_connection_proxy (connection , db_integration )
243+
244+ get_cnx_proxy = get_cnx_proxy or get_traced_connection_proxy
245+ return get_cnx_proxy (connection , db_integration )
234246
235247
236248def uninstrument_connection (connection ):
0 commit comments