Skip to content

Commit

Permalink
Jedis 3.0: extract net attributes from InetSocketAddress (#3912)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit committed Aug 23, 2021
1 parent 1fe4bfb commit 662e2e8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand All @@ -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
}
}
}
Expand All @@ -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
}
}
}
Expand All @@ -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
}
}
}
Expand All @@ -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
}
}
}
Expand Down

0 comments on commit 662e2e8

Please sign in to comment.