Skip to content

Commit d5525e2

Browse files
committed
fix: enhance RpcEndpointAspect to handle JsonRpcPoolTransporter results and improve context setting
1 parent 87344e3 commit d5525e2

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/sentry/src/Tracing/Aspect/RpcEndpointAspect.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)