Skip to content
Open
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 @@ -34,9 +34,9 @@
import io.grpc.ClientInterceptor;
import io.grpc.ForwardingClientCall.SimpleForwardingClientCall;
import io.grpc.ForwardingClientCallListener.SimpleForwardingClientCallListener;
import io.grpc.Grpc;
import io.grpc.Metadata;
import io.grpc.MethodDescriptor;
import io.grpc.alts.AltsContextUtil;
import io.opencensus.stats.MeasureMap;
import io.opencensus.stats.Stats;
import io.opencensus.stats.StatsRecorder;
Expand All @@ -47,9 +47,6 @@
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.api.trace.Span;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
Expand Down Expand Up @@ -109,6 +106,7 @@ public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
@Override
public void start(Listener<RespT> responseListener, Metadata headers) {
try {
ClientCall<ReqT, RespT> call = this;
Span span = Span.current();
DatabaseName databaseName = extractDatabaseName(headers);
String key = extractKey(databaseName, method.getFullMethodName());
Expand All @@ -127,10 +125,9 @@ public void start(Listener<RespT> responseListener, Metadata headers) {
new SimpleForwardingClientCallListener<RespT>(responseListener) {
@Override
public void onHeaders(Metadata metadata) {
Boolean isDirectPathUsed =
isDirectPathUsed(getAttributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR));
// Check if the call uses DirectPath by inspecting the ALTS context.
boolean isDirectPathUsed = AltsContextUtil.check(call);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can call AltsContextUtil.check(getAttributes()). This will avoid storing clientcall object

addDirectPathUsedAttribute(compositeTracer, isDirectPathUsed);

processHeader(
metadata, tagContext, attributes, span, compositeTracer, isDirectPathUsed);
super.onHeaders(metadata);
Expand Down Expand Up @@ -316,14 +313,4 @@ private void addDirectPathUsedAttribute(
BuiltInMetricsConstant.DIRECT_PATH_USED_KEY.getKey(), Boolean.toString(isDirectPathUsed));
}
}

private Boolean isDirectPathUsed(SocketAddress remoteAddr) {
if (remoteAddr instanceof InetSocketAddress) {
InetAddress inetAddress = ((InetSocketAddress) remoteAddr).getAddress();
String addr = inetAddress.getHostAddress();
return addr.startsWith(BuiltInMetricsConstant.DP_IPV4_PREFIX)
|| addr.startsWith(BuiltInMetricsConstant.DP_IPV6_PREFIX);
}
return false;
}
}
Loading