Skip to content

Commit 13021ee

Browse files
committed
Update trace span attributes to follow latest OTel semantic conventions (1.22.0)
1 parent eba436c commit 13021ee

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

jdbc/driver/mysql_telemetry.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ namespace telemetry
8484
}
8585

8686

87+
/*
88+
Note: See [1] for relevant OTel semantic conventions for connection-level
89+
attributes.
90+
91+
[1] https://github.com/open-telemetry/semantic-conventions/blob/main/docs/database/database-spans.md#connection-level-attributes
92+
*/
93+
8794
void
8895
Telemetry_base<MySQL_Connection>::set_attribs(
8996
MySQL_Connection* con,
@@ -98,19 +105,23 @@ namespace telemetry
98105
switch(endpoint.Protocol())
99106
{
100107
case NativeAPI::PROTOCOL_TCP:
101-
transport = "ip_tcp";
108+
transport = "tcp";
109+
// TODO: If we can somehow detect IPv6 connections then "network.type"
110+
// should be set to "ipv6"
111+
span->SetAttribute("network.type", "ipv4");
102112
break;
103113
case NativeAPI::PROTOCOL_SOCKET:
104-
span->SetAttribute("net.sock.family", "unix");
114+
transport = "socket";
115+
span->SetAttribute("network.type", "unix");
105116
case NativeAPI::PROTOCOL_PIPE:
106117
transport = "pipe";
107118
break;
108119
default:
109120
transport = "other";
110121
}
111122

112-
span->SetAttribute("net.transport", transport);
113-
span->SetAttribute("net.peer.name", endpoint.Host().c_str());
123+
span->SetAttribute("network.transport", transport);
124+
span->SetAttribute("server.address", endpoint.Host().c_str());
114125

115126
/*
116127
Note: `endpoint.hasPort()` alone is not good because it tells whether
@@ -122,7 +133,7 @@ namespace telemetry
122133

123134
if (options.count(OPT_PORT) || endpoint.hasPort())
124135
{
125-
span->SetAttribute("net.peer.port", endpoint.Port());
136+
span->SetAttribute("server.port", endpoint.Port());
126137
}
127138
}
128139

0 commit comments

Comments
 (0)