Jedis 3.0: extract net attributes from InetSocketAddress
MODIFY
instrumentation/jedis/jedis-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/JedisNetAttributesExtractor.java
instrumentation/jedis/jedis-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/JedisNetAttributesExtractor.java
package io.opentelemetry.javaagent.instrumentation.jedis.v3_0;
-import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor;
+import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetAttributesExtractor;
+import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
+import java.net.InetSocketAddress;
+import java.net.Socket;
import org.checkerframework.checker.nullness.qual.Nullable;
-final class JedisNetAttributesExtractor extends NetAttributesExtractor<JedisRequest, Void> {
+final class JedisNetAttributesExtractor
+ extends InetSocketAddressNetAttributesExtractor<JedisRequest, Void> {
@Override
- @Nullable
- public String transport(JedisRequest request) {
- return null;
- }
-
- @Override
- public String peerName(JedisRequest request, @Nullable Void unused) {
- return request.getConnection().getHost();
+ public @Nullable InetSocketAddress getAddress(JedisRequest jedisRequest, @Nullable Void unused) {
+ Socket socket = jedisRequest.getConnection().getSocket();
+ if (socket != null && socket.getRemoteSocketAddress() instanceof InetSocketAddress) {
+ return (InetSocketAddress) socket.getRemoteSocketAddress();
}
-
- @Override
- public Integer peerPort(JedisRequest request, @Nullable Void unused) {
- return request.getConnection().getPort();
+ return null;
}
@Override
- @Nullable
- public String peerIp(JedisRequest request, @Nullable Void unused) {
- return null;
+ public String transport(JedisRequest jedisRequest) {
+ return SemanticAttributes.NetTransportValues.IP_TCP;
}
}

MODIFY
instrumentation/jedis/jedis-3.0/javaagent/src/test/groovy/Jedis30ClientTest.groovy
instrumentation/jedis/jedis-3.0/javaagent/src/test/groovy/Jedis30ClientTest.groovy
@@ -53,6 +53,8 @@ class Jedis30ClientTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.DB_OPERATION.key" "SET"
"$SemanticAttributes.NET_PEER_NAME.key" "localhost"
"$SemanticAttributes.NET_PEER_PORT.key" port
+ "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
+ "${SemanticAttributes.NET_TRANSPORT}" SemanticAttributes.NetTransportValues.IP_TCP
}
}
}
@@ -78,6 +80,8 @@ class Jedis30ClientTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.DB_OPERATION.key" "SET"
"$SemanticAttributes.NET_PEER_NAME.key" "localhost"
"$SemanticAttributes.NET_PEER_PORT.key" port
+ "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
+ "${SemanticAttributes.NET_TRANSPORT}" SemanticAttributes.NetTransportValues.IP_TCP
}
}
}
@@ -91,6 +95,8 @@ class Jedis30ClientTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.DB_OPERATION.key" "GET"
"$SemanticAttributes.NET_PEER_NAME.key" "localhost"
"$SemanticAttributes.NET_PEER_PORT.key" port
+ "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
+ "${SemanticAttributes.NET_TRANSPORT}" SemanticAttributes.NetTransportValues.IP_TCP
}
}
}
@@ -116,6 +122,8 @@ class Jedis30ClientTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.DB_OPERATION.key" "SET"
"$SemanticAttributes.NET_PEER_NAME.key" "localhost"
"$SemanticAttributes.NET_PEER_PORT.key" port
+ "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
+ "${SemanticAttributes.NET_TRANSPORT}" SemanticAttributes.NetTransportValues.IP_TCP
}
}
}
@@ -129,6 +137,8 @@ class Jedis30ClientTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.DB_OPERATION.key" "RANDOMKEY"
"$SemanticAttributes.NET_PEER_NAME.key" "localhost"
"$SemanticAttributes.NET_PEER_PORT.key" port
+ "${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
+ "${SemanticAttributes.NET_TRANSPORT}" SemanticAttributes.NetTransportValues.IP_TCP
}
}
}

Jedis 3.0: extract net attributes from InetSocketAddress (#3912)