friendsofhyperf / components

🚀 The most popular components for Hyperf.
MIT License
78 stars 18 forks source link

sentry组件rpc调用问题 #704

Closed tw2066 closed 2 months ago

tw2066 commented 2 months ago

代码

控制器

   public function void()
    {
        $data = Db::table('admin')->first();
        $void = $this->idGenerator->void();
        dump($void);
        return 'void';
    }

rpc

    public function void()
    {
        $response = $this->client->create()->get('http://www.baidu.com/aaa');
        echo 'void...';
    }

services.php配置

    'consumers' => [
        [
            // name 需与服务提供者的 name 属性相同
            'name' => 'IdGenerateService',
            // 服务接口名,可选,默认值等于 name 配置的值,如果 name 直接定义为接口类则可忽略此行配置,如 name 为字符串则需要配置 service 对应到接口类
            'service' => App\Rpc\JsonRpc\IdGenerateInterface::class,
            // 服务提供者的服务协议,可选,默认值为 jsonrpc-http
            // 可选 jsonrpc-http jsonrpc jsonrpc-tcp-length-check
            'protocol' => 'jsonrpc-http',
            // 负载均衡算法,可选,默认值为 random
            'load_balancer' => 'random',
            // 如果没有指定上面的 registry 配置,即为直接对指定的节点进行消费,通过下面的 nodes 参数来配置服务提供者的节点信息
            'registry' => [
            ],
            'nodes' => [
                ['host' => '127.0.0.1', 'port' => 19587],
            ],
     ]
]
image

rpc调用 的位置存在(包含关系)问题

应该 skeleton.IdGenerateService//id_generate/void—/id_generate/void 包含 http.client—POST http://127.0.0.1:19587

huangdijia commented 2 months ago

@tw2066 你按 #705 本地修改一下,试试看是否正常

tw2066 commented 2 months ago

报错了

[AppExceptionHandler::handle] TypeError: str_contains(): Argument #1 ($haystack) must be of type string, array given in /Users/WWW/php-service/vendor/friendsofhyperf/sentry/src/Tracing/Aspect/GuzzleHttpClientAspect.php:54
Stack trace:
#0 /Users/WWW/php-service/vendor/friendsofhyperf/sentry/src/Tracing/Aspect/GuzzleHttpClientAspect.php(54): str_contains(Array, 'rpc')

代码

        // If the parent span is not exists or the parent span is belongs to rpc system, then skip.
        if (! $parent || str_contains($parent->getData('rpc.system'), 'rpc')) {
            return $proceedingJoinPoint->process();
        }

$parent->getData('rpc.system')返回的是数组

huangdijia commented 2 months ago

帮忙 dump 一下看看是怎么样的?我测试返回的是 string 哦

huangdijia commented 2 months ago

我调整了一下,直接判断 $parent->getData('rpc.system') 是否为空

tw2066 commented 2 months ago

返回的是 空数组

tw2066 commented 2 months ago
image
        $parent = SentrySdk::getCurrentHub()->getSpan();

        // If the parent span is not exists or the parent span is belongs to rpc system, then skip.
        if (! $parent || $parent->getData('rpc.system')) {
            return $proceedingJoinPoint->process();
        }

还是一样

huangdijia commented 2 months ago

空数组是不正常了,我再看看。

huangdijia commented 2 months ago

麻烦再按 PR 修改试试看

tw2066 commented 2 months ago

$parent = SentrySdk::getCurrentHub()->getSpan(); 51行 dump($parent->getData('rpc.system')); 还是空数组

结果和之前一样

huangdijia commented 2 months ago

RpcAspect 改了吗

tw2066 commented 2 months ago

改了的

huangdijia commented 2 months ago

找到问题了,麻烦再试试看。

tw2066 commented 2 months ago
image

@huangdijia

符合预期

http.client—POST http://127.0.0.1:19587 没有了

huangdijia commented 2 months ago

好的,我也发版了,你更新一下就可以了