@@ -60,49 +60,51 @@ async def main():
6060from opentelemetry .instrumentation .asyncpg .version import __version__
6161from opentelemetry .instrumentation .instrumentor import BaseInstrumentor
6262from opentelemetry .instrumentation .utils import unwrap
63- from opentelemetry .semconv .trace import (
63+ from opentelemetry .semconv ._incubating .attributes .db_attributes import (
64+ DB_NAME ,
65+ DB_STATEMENT ,
66+ DB_SYSTEM ,
67+ DB_USER ,
6468 DbSystemValues ,
69+ )
70+ from opentelemetry .semconv ._incubating .attributes .net_attributes import (
71+ NET_PEER_NAME ,
72+ NET_PEER_PORT ,
73+ NET_TRANSPORT ,
6574 NetTransportValues ,
66- SpanAttributes ,
6775)
6876from opentelemetry .trace import SpanKind
6977from opentelemetry .trace .status import Status , StatusCode
7078
7179
7280def _hydrate_span_from_args (connection , query , parameters ) -> dict :
7381 """Get network and database attributes from connection."""
74- span_attributes = {
75- SpanAttributes .DB_SYSTEM : DbSystemValues .POSTGRESQL .value
76- }
82+ span_attributes = {DB_SYSTEM : DbSystemValues .POSTGRESQL .value }
7783
7884 # connection contains _params attribute which is a namedtuple ConnectionParameters.
7985 # https://github.com/MagicStack/asyncpg/blob/master/asyncpg/connection.py#L68
8086
8187 params = getattr (connection , "_params" , None )
8288 dbname = getattr (params , "database" , None )
8389 if dbname :
84- span_attributes [SpanAttributes . DB_NAME ] = dbname
90+ span_attributes [DB_NAME ] = dbname
8591 user = getattr (params , "user" , None )
8692 if user :
87- span_attributes [SpanAttributes . DB_USER ] = user
93+ span_attributes [DB_USER ] = user
8894
8995 # connection contains _addr attribute which is either a host/port tuple, or unix socket string
9096 # https://magicstack.github.io/asyncpg/current/_modules/asyncpg/connection.html
9197 addr = getattr (connection , "_addr" , None )
9298 if isinstance (addr , tuple ):
93- span_attributes [SpanAttributes .NET_PEER_NAME ] = addr [0 ]
94- span_attributes [SpanAttributes .NET_PEER_PORT ] = addr [1 ]
95- span_attributes [SpanAttributes .NET_TRANSPORT ] = (
96- NetTransportValues .IP_TCP .value
97- )
99+ span_attributes [NET_PEER_NAME ] = addr [0 ]
100+ span_attributes [NET_PEER_PORT ] = addr [1 ]
101+ span_attributes [NET_TRANSPORT ] = NetTransportValues .IP_TCP .value
98102 elif isinstance (addr , str ):
99- span_attributes [SpanAttributes .NET_PEER_NAME ] = addr
100- span_attributes [SpanAttributes .NET_TRANSPORT ] = (
101- NetTransportValues .OTHER .value
102- )
103+ span_attributes [NET_PEER_NAME ] = addr
104+ span_attributes [NET_TRANSPORT ] = NetTransportValues .OTHER .value
103105
104106 if query is not None :
105- span_attributes [SpanAttributes . DB_STATEMENT ] = query
107+ span_attributes [DB_STATEMENT ] = query
106108
107109 if parameters is not None and len (parameters ) > 0 :
108110 span_attributes ["db.statement.parameters" ] = str (parameters )
0 commit comments