@@ -193,11 +193,7 @@ def test_instrument_connection(self):
193193 self .assertEqual (len (spans_list ), 0 )
194194
195195 instrumentor = Psycopg2Instrumentor ()
196- original_cursor_factory = cnx .cursor_factory
197196 cnx = instrumentor .instrument_connection (cnx )
198- self .assertEqual (
199- instrumentor ._otel_cursor_factories [cnx ], original_cursor_factory
200- )
201197 cursor = cnx .cursor ()
202198 cursor .execute (query )
203199
@@ -218,17 +214,8 @@ def test_instrument_connection_with_instrument(self):
218214 instrumentor .instrument ()
219215
220216 cnx = psycopg2 .connect (database = "test" )
221- original_cursor_factory = cnx .cursor_factory
222- orig_cnx = cnx
223217 cnx = Psycopg2Instrumentor ().instrument_connection (cnx )
224218
225- # TODO Should not set cursor_factory if already instrumented
226- # https://github.com/open-telemetry/opentelemetry-python-contrib/issues/3138
227- # self.assertEqual(instrumentor._otel_cursor_factories[cnx], None)
228- self .assertEqual (
229- instrumentor ._otel_cursor_factories .get (orig_cnx ),
230- original_cursor_factory ,
231- )
232219 cursor = cnx .cursor ()
233220 cursor .execute (query )
234221
@@ -248,23 +235,11 @@ def test_instrument_connection_with_instrument_connection(self):
248235 self .assertEqual (len (spans_list ), 0 )
249236
250237 cnx = psycopg2 .connect (database = "test" )
251- original_cursor_factory = cnx .cursor_factory
252238 instrumentor = Psycopg2Instrumentor ()
253- orig_cnx = cnx
254239 cnx = instrumentor .instrument_connection (cnx )
255- self .assertEqual (
256- instrumentor ._otel_cursor_factories .get (orig_cnx ),
257- original_cursor_factory ,
258- )
259240
260- orig_cnx = cnx
261- original_cursor_factory = cnx .cursor_factory
262241 instrumentor = Psycopg2Instrumentor ()
263242 cnx = instrumentor .instrument_connection (cnx )
264- self .assertEqual (
265- instrumentor ._otel_cursor_factories .get (orig_cnx ),
266- original_cursor_factory ,
267- )
268243 cursor = cnx .cursor ()
269244 cursor .execute (query )
270245
@@ -290,13 +265,14 @@ def test_uninstrument_connection_with_instrument(self):
290265 cursor = cnx .cursor ()
291266 cursor .execute (query )
292267
293- spans_list = self .memory_exporter .get_finished_spans ()
294- self .assertEqual (len (spans_list ), 1 )
268+ # TODO Add check for attempt to instrument a connection when already instrumented
269+ # https://github.com/open-telemetry/opentelemetry-python-contrib/issues/3138
270+ # spans_list = self.memory_exporter.get_finished_spans()
271+ # self.assertEqual(len(spans_list), 1)
295272
296273 # pylint: disable=unused-argument
297274 def test_uninstrument_connection_with_instrument_connection (self ):
298275 cnx = psycopg2 .connect (database = "test" )
299- original_cursor_factory = cnx .cursor_factory
300276 instrumentor = Psycopg2Instrumentor ()
301277 instrumentor .instrument_connection (cnx )
302278 query = "SELECT * FROM test"
@@ -305,20 +281,15 @@ def test_uninstrument_connection_with_instrument_connection(self):
305281
306282 spans_list = self .memory_exporter .get_finished_spans ()
307283 self .assertEqual (len (spans_list ), 1 )
308- self .assertEqual (
309- instrumentor ._otel_cursor_factories [cnx ], original_cursor_factory
310- )
311284
312- orig_cnx = cnx
313285 cnx = Psycopg2Instrumentor ().uninstrument_connection (cnx )
314286 cursor = cnx .cursor ()
315287 cursor .execute (query )
316288
317- spans_list = self .memory_exporter .get_finished_spans ()
318- self .assertEqual (len (spans_list ), 1 )
319- self .assertEqual (
320- instrumentor ._otel_cursor_factories .get (orig_cnx ), None
321- )
289+ # TODO Add check for attempt to instrument a connection when already instrumented
290+ # https://github.com/open-telemetry/opentelemetry-python-contrib/issues/3138
291+ # spans_list = self.memory_exporter.get_finished_spans()
292+ # self.assertEqual(len(spans_list), 1)
322293
323294 @mock .patch ("opentelemetry.instrumentation.dbapi.wrap_connect" )
324295 def test_sqlcommenter_enabled (self , event_mocked ):
0 commit comments