Skip to content

Commit 2b31ba0

Browse files
committed
feat: 添加gRPC服务器地址和端口到追踪数据
1 parent 7fb2775 commit 2b31ba0

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/Tracing/Aspect/GrpcAspect.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use FriendsOfHyperf\Sentry\Feature;
1616
use Hyperf\Di\Aop\AbstractAspect;
1717
use Hyperf\Di\Aop\ProceedingJoinPoint;
18+
use Hyperf\GrpcClient\BaseClient;
19+
use Hyperf\GrpcClient\GrpcClient;
1820
use Sentry\SentrySdk;
1921
use Sentry\State\Scope;
2022
use Sentry\Tracing\SpanContext;
@@ -38,12 +40,20 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
3840
return $proceedingJoinPoint->process();
3941
}
4042

43+
/** @var BaseClient $instance */
44+
$instance = $proceedingJoinPoint->getInstance();
45+
/** @var GrpcClient $grpcClient */
46+
$grpcClient = $instance->_getGrpcClient();
47+
[$serverAddress, $serverPort] = (fn () => [$this->host ?? null, $this->port ?? null])->call($grpcClient);
48+
4149
$method = $proceedingJoinPoint->arguments['keys']['method'];
4250
$options = $proceedingJoinPoint->arguments['keys']['options'];
4351
$data = [
4452
'rpc.system' => 'grpc',
4553
'rpc.method' => $method,
4654
'rpc.options' => $options,
55+
'server.address' => $serverAddress,
56+
'server.port' => $serverPort,
4757
];
4858

4959
$parent = SentrySdk::getCurrentHub()->getSpan();

0 commit comments

Comments
 (0)