@@ -60,49 +60,51 @@ async def main():
60
60
from opentelemetry .instrumentation .asyncpg .version import __version__
61
61
from opentelemetry .instrumentation .instrumentor import BaseInstrumentor
62
62
from 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 ,
64
68
DbSystemValues ,
69
+ )
70
+ from opentelemetry .semconv ._incubating .attributes .net_attributes import (
71
+ NET_PEER_NAME ,
72
+ NET_PEER_PORT ,
73
+ NET_TRANSPORT ,
65
74
NetTransportValues ,
66
- SpanAttributes ,
67
75
)
68
76
from opentelemetry .trace import SpanKind
69
77
from opentelemetry .trace .status import Status , StatusCode
70
78
71
79
72
80
def _hydrate_span_from_args (connection , query , parameters ) -> dict :
73
81
"""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 }
77
83
78
84
# connection contains _params attribute which is a namedtuple ConnectionParameters.
79
85
# https://github.com/MagicStack/asyncpg/blob/master/asyncpg/connection.py#L68
80
86
81
87
params = getattr (connection , "_params" , None )
82
88
dbname = getattr (params , "database" , None )
83
89
if dbname :
84
- span_attributes [SpanAttributes . DB_NAME ] = dbname
90
+ span_attributes [DB_NAME ] = dbname
85
91
user = getattr (params , "user" , None )
86
92
if user :
87
- span_attributes [SpanAttributes . DB_USER ] = user
93
+ span_attributes [DB_USER ] = user
88
94
89
95
# connection contains _addr attribute which is either a host/port tuple, or unix socket string
90
96
# https://magicstack.github.io/asyncpg/current/_modules/asyncpg/connection.html
91
97
addr = getattr (connection , "_addr" , None )
92
98
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
98
102
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
103
105
104
106
if query is not None :
105
- span_attributes [SpanAttributes . DB_STATEMENT ] = query
107
+ span_attributes [DB_STATEMENT ] = query
106
108
107
109
if parameters is not None and len (parameters ) > 0 :
108
110
span_attributes ["db.statement.parameters" ] = str (parameters )
0 commit comments