friendsofhyperf/telescope

hyperf 框架的优雅调试助手。

资助包维护!
huangdijia
hdj.me/sponsors

安装数: 1,153

依赖项: 0

建议者: 0

安全: 0

星标: 7

关注者: 2

分支: 1

语言:Vue

v3.1.31 2024-06-23 14:00 UTC

README

hyperf 框架的优雅调试助手。

功能

  • request
  • exception
  • sql
  • grpc 服务器/客户端
  • redis
  • 日志
  • 命令
  • 事件
  • guzzle
  • 缓存
  • rpc 服务器/客户端

安装

composer require friendsofhyperf/telescope:~3.1.0

发布

php bin/hyperf.php vendor:publish friendsofhyperf/telescope

迁移

php bin/hyperf.php migrate

添加监听器

<?php

// config/autoload/listeners.php

return [
    FriendsOfHyperf\Telescope\Listener\RequestHandledListener::class,
];

添加中间件

<?php

// config/autoload/middlewares.php

return [
    'grpc' => [
        FriendsOfHyperf\Telescope\Middleware\TelescopeMiddleware::class,
    ],
];

TelescopeMiddleware 或 RequestHandledListener,您可以选择其中之一。

添加环境变量

# telescope
TELESCOPE_DB_CONNECTION=default

TELESCOPE_ENABLE_REQUEST=true
TELESCOPE_ENABLE_COMMAND=true
TELESCOPE_ENABLE_GRPC=true
TELESCOPE_ENABLE_LOG=true
TELESCOPE_ENABLE_REDIS=true
TELESCOPE_ENABLE_EVENT=true
TELESCOPE_ENABLE_EXCEPTION=true
TELESCOPE_ENABLE_JOB=true
TELESCOPE_ENABLE_DB=true
TELESCOPE_ENABLE_GUZZLE=true
TELESCOPE_ENABLE_CACHE=true
TELESCOPE_ENABLE_RPC=true

TELESCOPE_SERVER_ENABLE=true

访问

http://127.0.0.1:9509/telescope/requests

标签

您可能希望为条目附加自定义标签。为此,您可以使用 Telescope::tag 方法。

过滤

您可能只想在特定条件下记录条目。为此,您可以使用 Telescope::filter 方法。

示例

use FriendsOfHyperf\Telescope\Telescope;
use Hyperf\Event\Contract\ListenerInterface;
use Hyperf\Framework\Event\BootApplication;
use FriendsOfHyperf\Telescope\IncomingEntry;

class TelescopeInitListener implements ListenerInterface
{
    public function listen(): array
    {
        return [
            BootApplication::class,
        ];
    }

    public function process(object $event): void
    {
        // attach your own custom tags
        Telescope::tag(function (IncomingEntry $entry) {
            if ($entry->type === 'request') {
                return [
                    'status:' . $entry->content['response_status'],
                    'uri:'. $entry->content['uri'],
                ];
            }
        });

        // filter entry
        Telescope::filter(function (IncomingEntry $entry): bool {
            if ($entry->type === 'request'){
                if ($entry->content['uri'] == 'xxxx') {
                    return false;
                }
            }
            return true;
        });

    }
}

您也可以在中间件中这样做。