Jedis 3.0: extract net attributes from InetSocketAddress (#3912)
This commit is contained in:
parent
1fe4bfb058
commit
662e2e8ab5
|
@ -5,30 +5,26 @@
|
||||||
|
|
||||||
package io.opentelemetry.javaagent.instrumentation.jedis.v3_0;
|
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;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
final class JedisNetAttributesExtractor extends NetAttributesExtractor<JedisRequest, Void> {
|
final class JedisNetAttributesExtractor
|
||||||
|
extends InetSocketAddressNetAttributesExtractor<JedisRequest, Void> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
public @Nullable InetSocketAddress getAddress(JedisRequest jedisRequest, @Nullable Void unused) {
|
||||||
public String transport(JedisRequest request) {
|
Socket socket = jedisRequest.getConnection().getSocket();
|
||||||
|
if (socket != null && socket.getRemoteSocketAddress() instanceof InetSocketAddress) {
|
||||||
|
return (InetSocketAddress) socket.getRemoteSocketAddress();
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String peerName(JedisRequest request, @Nullable Void unused) {
|
public String transport(JedisRequest jedisRequest) {
|
||||||
return request.getConnection().getHost();
|
return SemanticAttributes.NetTransportValues.IP_TCP;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Integer peerPort(JedisRequest request, @Nullable Void unused) {
|
|
||||||
return request.getConnection().getPort();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public String peerIp(JedisRequest request, @Nullable Void unused) {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,8 @@ class Jedis30ClientTest extends AgentInstrumentationSpecification {
|
||||||
"$SemanticAttributes.DB_OPERATION.key" "SET"
|
"$SemanticAttributes.DB_OPERATION.key" "SET"
|
||||||
"$SemanticAttributes.NET_PEER_NAME.key" "localhost"
|
"$SemanticAttributes.NET_PEER_NAME.key" "localhost"
|
||||||
"$SemanticAttributes.NET_PEER_PORT.key" port
|
"$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.DB_OPERATION.key" "SET"
|
||||||
"$SemanticAttributes.NET_PEER_NAME.key" "localhost"
|
"$SemanticAttributes.NET_PEER_NAME.key" "localhost"
|
||||||
"$SemanticAttributes.NET_PEER_PORT.key" port
|
"$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.DB_OPERATION.key" "GET"
|
||||||
"$SemanticAttributes.NET_PEER_NAME.key" "localhost"
|
"$SemanticAttributes.NET_PEER_NAME.key" "localhost"
|
||||||
"$SemanticAttributes.NET_PEER_PORT.key" port
|
"$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.DB_OPERATION.key" "SET"
|
||||||
"$SemanticAttributes.NET_PEER_NAME.key" "localhost"
|
"$SemanticAttributes.NET_PEER_NAME.key" "localhost"
|
||||||
"$SemanticAttributes.NET_PEER_PORT.key" port
|
"$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.DB_OPERATION.key" "RANDOMKEY"
|
||||||
"$SemanticAttributes.NET_PEER_NAME.key" "localhost"
|
"$SemanticAttributes.NET_PEER_NAME.key" "localhost"
|
||||||
"$SemanticAttributes.NET_PEER_PORT.key" port
|
"$SemanticAttributes.NET_PEER_PORT.key" port
|
||||||
|
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
|
||||||
|
"${SemanticAttributes.NET_TRANSPORT}" SemanticAttributes.NetTransportValues.IP_TCP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue