@@ -258,6 +258,25 @@ def test_span_name(self):
258
258
self .assertEqual (spans_list [6 ].name , "postgresql" )
259
259
self .assertEqual (spans_list [7 ].name , "--" )
260
260
261
+ def test_span_params_attribute (self ):
262
+ PsycopgInstrumentor ().instrument (capture_parameters = True )
263
+ cnx = psycopg .connect (database = "test" )
264
+ query = "SELECT * FROM mytable WHERE myparam1 = %s AND myparam2 = %s"
265
+ params = ("test" , 42 )
266
+
267
+ cursor = cnx .cursor ()
268
+
269
+ cursor .execute (query , params )
270
+ spans_list = self .memory_exporter .get_finished_spans ()
271
+ self .assertEqual (len (spans_list ), 1 )
272
+ self .assertEqual (spans_list [0 ].name , "SELECT" )
273
+ assert spans_list [0 ].attributes is not None
274
+ self .assertEqual (spans_list [0 ].attributes ["db.statement" ], query )
275
+ self .assertEqual (
276
+ spans_list [0 ].attributes ["db.statement.parameters" ],
277
+ str (params )
278
+ )
279
+
261
280
# pylint: disable=unused-argument
262
281
def test_not_recording (self ):
263
282
mock_tracer = mock .Mock ()
@@ -473,6 +492,25 @@ async def test_span_name_async(self):
473
492
self .assertEqual (spans_list [4 ].name , "query" )
474
493
self .assertEqual (spans_list [5 ].name , "query" )
475
494
495
+ async def test_span_params_attribute (self ):
496
+ PsycopgInstrumentor ().instrument (capture_parameters = True )
497
+ cnx = await psycopg .AsyncConnection .connect ("test" )
498
+ query = "SELECT * FROM mytable WHERE myparam1 = %s AND myparam2 = %s"
499
+ params = ("test" , 42 )
500
+ async with cnx .cursor () as cursor :
501
+
502
+ await cursor .execute (query , params )
503
+
504
+ spans_list = self .memory_exporter .get_finished_spans ()
505
+ self .assertEqual (len (spans_list ), 1 )
506
+ self .assertEqual (spans_list [0 ].name , "SELECT" )
507
+ assert spans_list [0 ].attributes is not None
508
+ self .assertEqual (spans_list [0 ].attributes ["db.statement" ], query )
509
+ self .assertEqual (
510
+ spans_list [0 ].attributes ["db.statement.parameters" ],
511
+ str (params )
512
+ )
513
+
476
514
# pylint: disable=unused-argument
477
515
async def test_not_recording_async (self ):
478
516
mock_tracer = mock .Mock ()
0 commit comments