@@ -456,12 +456,11 @@ def test_executemany_comment_stmt_enabled_matches_db_statement_attribute(
456
456
).group ()
457
457
self .assertEqual (cursor_span_id , db_statement_span_id )
458
458
459
- def test_compatible_build_version_psycopg_psycopg2_libpq (self ):
459
+ def test_compatible_build_version_psycopg2_libpq (self ):
460
460
connect_module = mock .MagicMock ()
461
461
connect_module .__name__ = "test"
462
462
connect_module .__version__ = mock .MagicMock ()
463
- connect_module .pq = mock .MagicMock ()
464
- connect_module .pq .__build_version__ = 123
463
+ connect_module .__libpq_version__ = 123
465
464
connect_module .apilevel = 123
466
465
connect_module .threadsafety = 123
467
466
connect_module .paramstyle = "test"
@@ -490,14 +489,46 @@ def test_compatible_build_version_psycopg_psycopg2_libpq(self):
490
489
"Select 1;" ,
491
490
)
492
491
493
- def test_compatible_build_version_psycopg_psycopg2_libpq_stmt_enabled (
492
+ def test_compatible_build_version_psycopg_libpq (self ):
493
+ connect_module = mock .MagicMock ()
494
+ connect_module .__name__ = "test"
495
+ connect_module .__version__ = mock .MagicMock ()
496
+ connect_module .pq .version .return_value = 123
497
+ connect_module .apilevel = 123
498
+ connect_module .threadsafety = 123
499
+ connect_module .paramstyle = "test"
500
+
501
+ db_integration = dbapi .DatabaseApiIntegration (
502
+ "instrumenting_module_test_name" ,
503
+ "postgresql" ,
504
+ enable_commenter = True ,
505
+ commenter_options = {"db_driver" : False , "dbapi_level" : False },
506
+ connect_module = connect_module ,
507
+ )
508
+ mock_connection = db_integration .wrapped_connection (
509
+ mock_connect , {}, {}
510
+ )
511
+ cursor = mock_connection .cursor ()
512
+ cursor .executemany ("Select 1;" )
513
+ self .assertRegex (
514
+ cursor .query ,
515
+ r"Select 1 /\*dbapi_threadsafety=123,driver_paramstyle='test',libpq_version=123,traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/;" ,
516
+ )
517
+ spans_list = self .memory_exporter .get_finished_spans ()
518
+ self .assertEqual (len (spans_list ), 1 )
519
+ span = spans_list [0 ]
520
+ self .assertEqual (
521
+ span .attributes [SpanAttributes .DB_STATEMENT ],
522
+ "Select 1;" ,
523
+ )
524
+
525
+ def test_no_build_version_where_we_dont_instrument_the_root_module (
494
526
self ,
495
527
):
496
528
connect_module = mock .MagicMock ()
497
529
connect_module .__name__ = "test"
498
530
connect_module .__version__ = mock .MagicMock ()
499
531
connect_module .pq = mock .MagicMock ()
500
- connect_module .pq .__build_version__ = 123
501
532
connect_module .apilevel = 123
502
533
connect_module .threadsafety = 123
503
534
connect_module .paramstyle = "test"
@@ -517,14 +548,14 @@ def test_compatible_build_version_psycopg_psycopg2_libpq_stmt_enabled(
517
548
cursor .executemany ("Select 1;" )
518
549
self .assertRegex (
519
550
cursor .query ,
520
- r"Select 1 /\*dbapi_threadsafety=123,driver_paramstyle='test',libpq_version=123, traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/;" ,
551
+ r"Select 1 /\*dbapi_threadsafety=123,driver_paramstyle='test',traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/;" ,
521
552
)
522
553
spans_list = self .memory_exporter .get_finished_spans ()
523
554
self .assertEqual (len (spans_list ), 1 )
524
555
span = spans_list [0 ]
525
556
self .assertRegex (
526
557
span .attributes [SpanAttributes .DB_STATEMENT ],
527
- r"Select 1 /\*dbapi_threadsafety=123,driver_paramstyle='test',libpq_version=123, traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/;" ,
558
+ r"Select 1 /\*dbapi_threadsafety=123,driver_paramstyle='test',traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/;" ,
528
559
)
529
560
530
561
def test_executemany_psycopg2_integration_comment (self ):
0 commit comments