diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/AbstractRpcClient.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/AbstractRpcClient.java index 08445aa8d405..a1200ff99cd4 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/AbstractRpcClient.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/AbstractRpcClient.java @@ -397,7 +397,9 @@ private Call callMethod(final Descriptors.MethodDescriptor md, final HBaseRpcCon final RpcCallback callback) { Span span = TraceUtil.createSpan("RpcClient.callMethod") .setAttribute(TraceUtil.RPC_SERVICE_KEY, md.getService().getName()) - .setAttribute(TraceUtil.RPC_METHOD_KEY, md.getName()); + .setAttribute(TraceUtil.RPC_METHOD_KEY, md.getName()) + .setAttribute(TraceUtil.REMOTE_HOST_KEY, addr.getHostName()) + .setAttribute(TraceUtil.REMOTE_PORT_KEY, addr.getPort()); try (Scope scope = span.makeCurrent()) { final MetricsConnection.CallStats cs = MetricsConnection.newCallStats(); cs.setStartTime(EnvironmentEdgeManager.currentTime()); diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/trace/TraceUtil.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/trace/TraceUtil.java index d0da07103131..8eb2399a5ecf 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/trace/TraceUtil.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/trace/TraceUtil.java @@ -54,6 +54,10 @@ public final class TraceUtil { public static final AttributeKey SERVER_NAME_KEY = AttributeKey.stringKey("db.hbase.server.name"); + public static final AttributeKey REMOTE_HOST_KEY = SemanticAttributes.NET_PEER_NAME; + + public static final AttributeKey REMOTE_PORT_KEY = SemanticAttributes.NET_PEER_PORT; + private TraceUtil() { } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/AbstractTestIPC.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/AbstractTestIPC.java index 4aca76400311..ffecb094dcf8 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/AbstractTestIPC.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/AbstractTestIPC.java @@ -455,11 +455,14 @@ private SpanData waitSpan(String name) { return traceRule.getSpans().stream().filter(s -> s.getName().equals(name)).findFirst().get(); } - private void assertRpcAttribute(SpanData data, String methodName) { + private void assertRpcAttribute(SpanData data, String methodName, InetSocketAddress addr) { assertEquals(SERVICE.getDescriptorForType().getName(), data.getAttributes().get(TraceUtil.RPC_SERVICE_KEY)); - assertEquals(methodName, - data.getAttributes().get(TraceUtil.RPC_METHOD_KEY)); + assertEquals(methodName, data.getAttributes().get(TraceUtil.RPC_METHOD_KEY)); + if (addr != null) { + assertEquals(addr.getHostName(), data.getAttributes().get(TraceUtil.REMOTE_HOST_KEY)); + assertEquals(addr.getPort(), data.getAttributes().get(TraceUtil.REMOTE_PORT_KEY).intValue()); + } } @Test @@ -471,8 +474,8 @@ public void testTracing() throws IOException, ServiceException { rpcServer.start(); BlockingInterface stub = newBlockingStub(client, rpcServer.getListenerAddress()); stub.pause(null, PauseRequestProto.newBuilder().setMs(100).build()); - assertRpcAttribute(waitSpan("RpcClient.callMethod"), "pause"); - assertRpcAttribute(waitSpan("RpcServer.callMethod"), "pause"); + assertRpcAttribute(waitSpan("RpcClient.callMethod"), "pause", rpcServer.getListenerAddress()); + assertRpcAttribute(waitSpan("RpcServer.callMethod"), "pause", null); assertSameTraceId(); for (SpanData data : traceRule.getSpans()) { assertThat( @@ -484,8 +487,8 @@ public void testTracing() throws IOException, ServiceException { traceRule.clearSpans(); assertThrows(ServiceException.class, () -> stub.error(null, EmptyRequestProto.getDefaultInstance())); - assertRpcAttribute(waitSpan("RpcClient.callMethod"), "error"); - assertRpcAttribute(waitSpan("RpcServer.callMethod"), "error"); + assertRpcAttribute(waitSpan("RpcClient.callMethod"), "error", rpcServer.getListenerAddress()); + assertRpcAttribute(waitSpan("RpcServer.callMethod"), "error", null); assertSameTraceId(); for (SpanData data : traceRule.getSpans()) { assertEquals(StatusCode.ERROR, data.getStatus().getStatusCode());