@@ -60,49 +60,50 @@ 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 (
64- DbSystemValues ,
65- NetTransportValues ,
66- SpanAttributes ,
63+ from opentelemetry .semconv ._incubating . attributes . db_attributes import (
64+ DB_NAME ,
65+ DB_STATEMENT ,
66+ DB_USER ,
6767)
68+ from opentelemetry .semconv ._incubating .attributes .net_attributes import (
69+ NET_PEER_NAME ,
70+ NET_PEER_PORT ,
71+ NET_TRANSPORT ,
72+ )
73+ from opentelemetry .semconv .attributes .db_attributes import DB_SYSTEM_NAME
74+ from opentelemetry .semconv .trace import DbSystemValues , NetTransportValues
6875from opentelemetry .trace import SpanKind
6976from opentelemetry .trace .status import Status , StatusCode
7077
7178
7279def _hydrate_span_from_args (connection , query , parameters ) -> dict :
7380 """Get network and database attributes from connection."""
74- span_attributes = {
75- SpanAttributes .DB_SYSTEM : DbSystemValues .POSTGRESQL .value
76- }
81+ span_attributes = {DB_SYSTEM_NAME : DbSystemValues .POSTGRESQL .value }
7782
7883 # connection contains _params attribute which is a namedtuple ConnectionParameters.
7984 # https://github.com/MagicStack/asyncpg/blob/master/asyncpg/connection.py#L68
8085
8186 params = getattr (connection , "_params" , None )
8287 dbname = getattr (params , "database" , None )
8388 if dbname :
84- span_attributes [SpanAttributes . DB_NAME ] = dbname
89+ span_attributes [DB_NAME ] = dbname
8590 user = getattr (params , "user" , None )
8691 if user :
87- span_attributes [SpanAttributes . DB_USER ] = user
92+ span_attributes [DB_USER ] = user
8893
8994 # connection contains _addr attribute which is either a host/port tuple, or unix socket string
9095 # https://magicstack.github.io/asyncpg/current/_modules/asyncpg/connection.html
9196 addr = getattr (connection , "_addr" , None )
9297 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- )
98+ span_attributes [NET_PEER_NAME ] = addr [0 ]
99+ span_attributes [NET_PEER_PORT ] = addr [1 ]
100+ span_attributes [NET_TRANSPORT ] = NetTransportValues .IP_TCP .value
98101 elif isinstance (addr , str ):
99- span_attributes [SpanAttributes .NET_PEER_NAME ] = addr
100- span_attributes [SpanAttributes .NET_TRANSPORT ] = (
101- NetTransportValues .OTHER .value
102- )
102+ span_attributes [NET_PEER_NAME ] = addr
103+ span_attributes [NET_TRANSPORT ] = NetTransportValues .OTHER .value
103104
104105 if query is not None :
105- span_attributes [SpanAttributes . DB_STATEMENT ] = query
106+ span_attributes [DB_STATEMENT ] = query
106107
107108 if parameters is not None and len (parameters ) > 0 :
108109 span_attributes ["db.statement.parameters" ] = str (parameters )
0 commit comments