109
109
from psycopg import ( # pylint: disable=import-self,no-name-in-module
110
110
AsyncCursor as pg_async_cursor ,
111
111
)
112
- from psycopg import Cursor as pg_cursor # pylint: disable=no-name-in-module,import-self
112
+ from psycopg import ( # pylint: disable=no-name-in-module,import-self
113
+ Cursor as pg_cursor ,
114
+ )
113
115
from psycopg .sql import Composed # pylint: disable=no-name-in-module
114
116
115
117
from opentelemetry .instrumentation import dbapi
@@ -182,7 +184,9 @@ def _instrument(self, **kwargs):
182
184
def _uninstrument (self , ** kwargs ):
183
185
""" "Disable Psycopg instrumentation"""
184
186
dbapi .unwrap_connect (psycopg , "connect" ) # pylint: disable=no-member
185
- dbapi .unwrap_connect (psycopg .Connection , "connect" ) # pylint: disable=no-member
187
+ dbapi .unwrap_connect (
188
+ psycopg .Connection , "connect" # pylint: disable=no-member
189
+ )
186
190
dbapi .unwrap_connect (
187
191
psycopg .AsyncConnection , "connect" # pylint: disable=no-member
188
192
)
@@ -194,7 +198,9 @@ def instrument_connection(connection, tracer_provider=None):
194
198
connection ._is_instrumented_by_opentelemetry = False
195
199
196
200
if not connection ._is_instrumented_by_opentelemetry :
197
- setattr (connection , _OTEL_CURSOR_FACTORY_KEY , connection .cursor_factory )
201
+ setattr (
202
+ connection , _OTEL_CURSOR_FACTORY_KEY , connection .cursor_factory
203
+ )
198
204
connection .cursor_factory = _new_cursor_factory (
199
205
tracer_provider = tracer_provider
200
206
)
@@ -208,7 +214,9 @@ def instrument_connection(connection, tracer_provider=None):
208
214
# TODO(owais): check if core dbapi can do this for all dbapi implementations e.g, pymysql and mysql
209
215
@staticmethod
210
216
def uninstrument_connection (connection ):
211
- connection .cursor_factory = getattr (connection , _OTEL_CURSOR_FACTORY_KEY , None )
217
+ connection .cursor_factory = getattr (
218
+ connection , _OTEL_CURSOR_FACTORY_KEY , None
219
+ )
212
220
213
221
return connection
214
222
@@ -244,7 +252,9 @@ async def wrapped_connection(
244
252
new_factory_kwargs = {"db_api" : self }
245
253
if base_cursor_factory :
246
254
new_factory_kwargs ["base_factory" ] = base_cursor_factory
247
- kwargs ["cursor_factory" ] = _new_cursor_async_factory (** new_factory_kwargs )
255
+ kwargs ["cursor_factory" ] = _new_cursor_async_factory (
256
+ ** new_factory_kwargs
257
+ )
248
258
connection = await connect_method (* args , ** kwargs )
249
259
self .get_connection_attributes (connection )
250
260
return connection
@@ -307,7 +317,9 @@ def callproc(self, *args, **kwargs):
307
317
return TracedCursorFactory
308
318
309
319
310
- def _new_cursor_async_factory (db_api = None , base_factory = None , tracer_provider = None ):
320
+ def _new_cursor_async_factory (
321
+ db_api = None , base_factory = None , tracer_provider = None
322
+ ):
311
323
if not db_api :
312
324
db_api = DatabaseApiAsyncIntegration (
313
325
__name__ ,
0 commit comments