Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jedis 3.0: extract net attributes from InetSocketAddress #3912

Merged
merged 1 commit into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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