@@ -29,15 +29,29 @@ class RpcEndpointAspect extends AbstractAspect
2929 public function process (ProceedingJoinPoint $ proceedingJoinPoint )
3030 {
3131 return tap ($ proceedingJoinPoint ->process (), function ($ result ) {
32+ // RpcMultiplex
3233 if ($ result instanceof \Hyperf \RpcMultiplex \Socket) {
3334 Context::set (Constants::TRACE_RPC_SERVER_ADDRESS , $ result ->getName ());
3435 Context::set (Constants::TRACE_RPC_SERVER_PORT , $ result ->getPort ());
3536 }
37+ // JsonRpcHttpTransporter
3638 if ($ result instanceof \Hyperf \LoadBalancer \Node) {
3739 Context::set (Constants::TRACE_RPC_SERVER_ADDRESS , $ result ->host );
3840 Context::set (Constants::TRACE_RPC_SERVER_PORT , $ result ->port );
3941 }
40- // todo: JsonRpcPoolTransporter::getConnection
42+ // JsonRpcPoolTransporter
43+ if ($ result instanceof \Hyperf \JsonRpc \Pool \RpcConnection) {
44+ /** @var null|\Hyperf\Engine\Contract\SocketInterface $socket */
45+ $ socket = (fn () => $ this ->connection ?? null )->call ($ result );
46+ if (method_exists ($ socket , 'getSocketOption ' )) {
47+ /** @var null|\Hyperf\Engine\Contract\Socket\SocketOptionInterface $option */
48+ $ option = $ socket ->getSocketOption ();
49+ if ($ option instanceof \Hyperf \Engine \Contract \Socket \SocketOptionInterface) {
50+ Context::set (Constants::TRACE_RPC_SERVER_ADDRESS , $ option ->getHost ());
51+ Context::set (Constants::TRACE_RPC_SERVER_PORT , $ option ->getPort ());
52+ }
53+ }
54+ }
4155 });
4256 }
4357}
0 commit comments