105
105
import typing
106
106
from typing import Collection
107
107
108
- import psycopg
109
- from psycopg import AsyncCursor as pg_async_cursor
110
- from psycopg import Cursor as pg_cursor # pylint: disable=no-name-in-module
108
+ import psycopg # pylint: disable=import-self
109
+ from psycopg import ( # pylint: disable=import-self,no-name-in-module
110
+ AsyncCursor as pg_async_cursor ,
111
+ )
112
+ from psycopg import Cursor as pg_cursor # pylint: disable=no-name-in-module,import-self
111
113
from psycopg .sql import Composed # pylint: disable=no-name-in-module
112
114
113
115
from opentelemetry .instrumentation import dbapi
@@ -154,7 +156,7 @@ def _instrument(self, **kwargs):
154
156
155
157
dbapi .wrap_connect (
156
158
__name__ ,
157
- psycopg .Connection ,
159
+ psycopg .Connection , # pylint: disable=no-member
158
160
"connect" ,
159
161
self ._DATABASE_SYSTEM ,
160
162
self ._CONNECTION_ATTRIBUTES ,
@@ -166,7 +168,7 @@ def _instrument(self, **kwargs):
166
168
)
167
169
dbapi .wrap_connect (
168
170
__name__ ,
169
- psycopg .AsyncConnection ,
171
+ psycopg .AsyncConnection , # pylint: disable=no-member
170
172
"connect" ,
171
173
self ._DATABASE_SYSTEM ,
172
174
self ._CONNECTION_ATTRIBUTES ,
@@ -179,9 +181,11 @@ def _instrument(self, **kwargs):
179
181
180
182
def _uninstrument (self , ** kwargs ):
181
183
""" "Disable Psycopg instrumentation"""
182
- dbapi .unwrap_connect (psycopg , "connect" )
183
- dbapi .unwrap_connect (psycopg .Connection , "connect" )
184
- dbapi .unwrap_connect (psycopg .AsyncConnection , "connect" )
184
+ dbapi .unwrap_connect (psycopg , "connect" ) # pylint: disable=no-member
185
+ dbapi .unwrap_connect (psycopg .Connection , "connect" ) # pylint: disable=no-member
186
+ dbapi .unwrap_connect (
187
+ psycopg .AsyncConnection , "connect" # pylint: disable=no-member
188
+ )
185
189
186
190
# TODO(owais): check if core dbapi can do this for all dbapi implementations e.g, pymysql and mysql
187
191
@staticmethod
@@ -190,9 +194,7 @@ def instrument_connection(connection, tracer_provider=None):
190
194
connection ._is_instrumented_by_opentelemetry = False
191
195
192
196
if not connection ._is_instrumented_by_opentelemetry :
193
- setattr (
194
- connection , _OTEL_CURSOR_FACTORY_KEY , connection .cursor_factory
195
- )
197
+ setattr (connection , _OTEL_CURSOR_FACTORY_KEY , connection .cursor_factory )
196
198
connection .cursor_factory = _new_cursor_factory (
197
199
tracer_provider = tracer_provider
198
200
)
@@ -206,9 +208,7 @@ def instrument_connection(connection, tracer_provider=None):
206
208
# TODO(owais): check if core dbapi can do this for all dbapi implementations e.g, pymysql and mysql
207
209
@staticmethod
208
210
def uninstrument_connection (connection ):
209
- connection .cursor_factory = getattr (
210
- connection , _OTEL_CURSOR_FACTORY_KEY , None
211
- )
211
+ connection .cursor_factory = getattr (connection , _OTEL_CURSOR_FACTORY_KEY , None )
212
212
213
213
return connection
214
214
@@ -244,9 +244,7 @@ async def wrapped_connection(
244
244
new_factory_kwargs = {"db_api" : self }
245
245
if base_cursor_factory :
246
246
new_factory_kwargs ["base_factory" ] = base_cursor_factory
247
- kwargs ["cursor_factory" ] = _new_cursor_async_factory (
248
- ** new_factory_kwargs
249
- )
247
+ kwargs ["cursor_factory" ] = _new_cursor_async_factory (** new_factory_kwargs )
250
248
connection = await connect_method (* args , ** kwargs )
251
249
self .get_connection_attributes (connection )
252
250
return connection
@@ -309,9 +307,7 @@ def callproc(self, *args, **kwargs):
309
307
return TracedCursorFactory
310
308
311
309
312
- def _new_cursor_async_factory (
313
- db_api = None , base_factory = None , tracer_provider = None
314
- ):
310
+ def _new_cursor_async_factory (db_api = None , base_factory = None , tracer_provider = None ):
315
311
if not db_api :
316
312
db_api = DatabaseApiAsyncIntegration (
317
313
__name__ ,
0 commit comments