@@ -264,6 +264,25 @@ def test_span_name(self):
264
264
self .assertEqual (spans_list [6 ].name , "postgresql" )
265
265
self .assertEqual (spans_list [7 ].name , "--" )
266
266
267
+ def test_span_params_attribute (self ):
268
+ PsycopgInstrumentor ().instrument (capture_parameters = True )
269
+ cnx = psycopg .connect (database = "test" )
270
+ query = "SELECT * FROM mytable WHERE myparam1 = %s AND myparam2 = %s"
271
+ params = ("test" , 42 )
272
+
273
+ cursor = cnx .cursor ()
274
+
275
+ cursor .execute (query , params )
276
+ spans_list = self .memory_exporter .get_finished_spans ()
277
+ self .assertEqual (len (spans_list ), 1 )
278
+ self .assertEqual (spans_list [0 ].name , "SELECT" )
279
+ assert spans_list [0 ].attributes is not None
280
+ self .assertEqual (spans_list [0 ].attributes ["db.statement" ], query )
281
+ self .assertEqual (
282
+ spans_list [0 ].attributes ["db.statement.parameters" ],
283
+ str (params )
284
+ )
285
+
267
286
# pylint: disable=unused-argument
268
287
def test_not_recording (self ):
269
288
mock_tracer = mock .Mock ()
@@ -479,6 +498,25 @@ async def test_span_name_async(self):
479
498
self .assertEqual (spans_list [4 ].name , "query" )
480
499
self .assertEqual (spans_list [5 ].name , "query" )
481
500
501
+ async def test_span_params_attribute (self ):
502
+ PsycopgInstrumentor ().instrument (capture_parameters = True )
503
+ cnx = await psycopg .AsyncConnection .connect ("test" )
504
+ query = "SELECT * FROM mytable WHERE myparam1 = %s AND myparam2 = %s"
505
+ params = ("test" , 42 )
506
+ async with cnx .cursor () as cursor :
507
+
508
+ await cursor .execute (query , params )
509
+
510
+ spans_list = self .memory_exporter .get_finished_spans ()
511
+ self .assertEqual (len (spans_list ), 1 )
512
+ self .assertEqual (spans_list [0 ].name , "SELECT" )
513
+ assert spans_list [0 ].attributes is not None
514
+ self .assertEqual (spans_list [0 ].attributes ["db.statement" ], query )
515
+ self .assertEqual (
516
+ spans_list [0 ].attributes ["db.statement.parameters" ],
517
+ str (params )
518
+ )
519
+
482
520
# pylint: disable=unused-argument
483
521
async def test_not_recording_async (self ):
484
522
mock_tracer = mock .Mock ()
0 commit comments