1212from opentelemetry .sdk .trace .export .in_memory_span_exporter import (
1313 InMemorySpanExporter ,
1414)
15+ from opentelemetry .semconv ._incubating .attributes .db_attributes import (
16+ DB_QUERY_PARAMETER_TEMPLATE ,
17+ )
1518from opentelemetry .semconv .trace import SpanAttributes
1619from opentelemetry .test .test_base import TestBase
1720from opentelemetry .trace import StatusCode
@@ -360,7 +363,7 @@ def test_instrumented_execute_method_with_arguments(self, *_, **__):
360363 spans [0 ].attributes [SpanAttributes .DB_STATEMENT ], "SELECT $1;"
361364 )
362365 self .assertEqual (
363- spans [0 ].attributes ["db.statement.parameters " ], "( '1',) "
366+ spans [0 ].attributes [f" { DB_QUERY_PARAMETER_TEMPLATE } .0 " ], "'1'"
364367 )
365368
366369 def test_instrumented_fetch_method_with_arguments (self , * _ , ** __ ):
@@ -375,7 +378,7 @@ def test_instrumented_fetch_method_with_arguments(self, *_, **__):
375378 spans [0 ].attributes [SpanAttributes .DB_STATEMENT ], "SELECT $1;"
376379 )
377380 self .assertEqual (
378- spans [0 ].attributes ["db.statement.parameters " ], "( '1',) "
381+ spans [0 ].attributes [f" { DB_QUERY_PARAMETER_TEMPLATE } .0 " ], "'1'"
379382 )
380383
381384 def test_instrumented_executemany_method_with_arguments (self , * _ , ** __ ):
@@ -389,7 +392,7 @@ def test_instrumented_executemany_method_with_arguments(self, *_, **__):
389392 spans [0 ].attributes [SpanAttributes .DB_STATEMENT ], "SELECT $1;"
390393 )
391394 self .assertEqual (
392- spans [0 ].attributes ["db.statement.parameters " ], "( [['1'], ['2']],) "
395+ spans [0 ].attributes [f" { DB_QUERY_PARAMETER_TEMPLATE } .0 " ], "[['1'], ['2']]"
393396 )
394397
395398 def test_instrumented_execute_interface_error_method (self , * _ , ** __ ):
@@ -404,7 +407,13 @@ def test_instrumented_execute_interface_error_method(self, *_, **__):
404407 spans [0 ].attributes [SpanAttributes .DB_STATEMENT ], "SELECT 42;"
405408 )
406409 self .assertEqual (
407- spans [0 ].attributes ["db.statement.parameters" ], "(1, 2, 3)"
410+ spans [0 ].attributes [f"{ DB_QUERY_PARAMETER_TEMPLATE } .0" ], "'1'"
411+ )
412+ self .assertEqual (
413+ spans [0 ].attributes [f"{ DB_QUERY_PARAMETER_TEMPLATE } .1" ], "2"
414+ )
415+ self .assertEqual (
416+ spans [0 ].attributes [f"{ DB_QUERY_PARAMETER_TEMPLATE } .2" ], "3"
408417 )
409418
410419 def test_instrumented_executemany_method_empty_query (self , * _ , ** __ ):
@@ -417,7 +426,7 @@ def test_instrumented_executemany_method_empty_query(self, *_, **__):
417426 self .assertEqual (spans [0 ].name , POSTGRES_DB_NAME )
418427 self .assertEqual (spans [0 ].attributes [SpanAttributes .DB_STATEMENT ], "" )
419428 self .assertEqual (
420- spans [0 ].attributes ["db.statement.parameters " ], "([],) "
429+ spans [0 ].attributes [f" { DB_QUERY_PARAMETER_TEMPLATE } .0 " ], "[] "
421430 )
422431
423432 def test_instrumented_fetch_method_broken_asyncpg (self , * _ , ** __ ):
@@ -489,7 +498,7 @@ async def _fake_execute(*args, **kwargs):
489498 SpanAttributes .NET_PEER_PORT : 5432 ,
490499 SpanAttributes .NET_TRANSPORT : "ip_tcp" ,
491500 SpanAttributes .DB_STATEMENT : "SELECT $1" ,
492- "db.statement.parameters " : "( '42',) " ,
501+ f" { DB_QUERY_PARAMETER_TEMPLATE } .0 " : "'42'" ,
493502 },
494503 )
495504 self .assertEqual (span .kind , trace .SpanKind .CLIENT )
@@ -523,7 +532,7 @@ async def _fake_cursor_execute(*args, **kwargs):
523532 SpanAttributes .NET_PEER_PORT : 5432 ,
524533 SpanAttributes .NET_TRANSPORT : "ip_tcp" ,
525534 SpanAttributes .DB_STATEMENT : "SELECT $1" ,
526- "db.statement.parameters " : "( '99',) " ,
535+ f" { DB_QUERY_PARAMETER_TEMPLATE } .0 " : "'99'" ,
527536 },
528537 )
529538 self .assertEqual (span .kind , trace .SpanKind .CLIENT )
0 commit comments