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

This commit is contained in:
Lauri Tulmin 2021-08-24 02:49:23 +03:00 committed by GitHub
parent 1fe4bfb058
commit 662e2e8ab5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 17 deletions

View File

@ -5,30 +5,26 @@
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) {
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();
}
return null;
}
@Override
public String peerName(JedisRequest request, @Nullable Void unused) {
return request.getConnection().getHost();
}
@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;
public String transport(JedisRequest jedisRequest) {
return SemanticAttributes.NetTransportValues.IP_TCP;
}
}

View File

@ -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
}
}
}