Skip to content

Commit b3a90c6

Browse files
Copilothuangdijia
andauthored
fix(telescope): register RequestHandledListener and SetRequestLifecycleListener in ConfigProvider (#1043)
* Initial plan * fix(telescope): auto-register RequestHandledListener and SetRequestLifecycleListener The listeners were missing from ConfigProvider causing exceptions and non-200 status codes to not be captured after upgrading to v3.1.76. Users had to manually add these listeners which was error-prone. Changes: - Add RequestHandledListener and SetRequestLifecycleListener to ConfigProvider - Update documentation to reflect automatic listener registration - Add test to verify listeners are properly registered Co-authored-by: huangdijia <[email protected]> * fix(telescope): 移除类名中的反斜杠以简化代码 * 删除 ConfigProviderTest.php 测试文件 --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: huangdijia <[email protected]>
1 parent c25cd11 commit b3a90c6

File tree

6 files changed

+24
-140
lines changed

6 files changed

+24
-140
lines changed

docs/en/components/telescope.md

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -34,39 +34,11 @@ php bin/hyperf.php migrate
3434

3535
## Usage
3636

37-
> Choose either the listener or middleware
37+
### Middleware (Optional for gRPC)
3838

39-
### Request Listener
39+
Add the middleware in the `config/autoload/middlewares.php` configuration file
4040

41-
Add the listener in the `config/autoload/listeners.php` configuration file
42-
43-
```php
44-
<?php
45-
46-
return [
47-
FriendsOfHyperf\Telescope\Listener\RequestHandledListener::class,
48-
FriendsOfHyperf\Telescope\Listener\SetRequestLifecycleListener::class,
49-
];
50-
51-
```
52-
53-
### Middleware
54-
55-
Add the global middleware in the `config/autoload/middlewares.php` configuration file
56-
57-
To record HTTP requests, use the `http` middleware
58-
59-
```php
60-
<?php
61-
62-
return [
63-
'http' => [
64-
FriendsOfHyperf\Telescope\Middleware\TelescopeMiddleware::class,
65-
],
66-
];
67-
```
68-
69-
To record gRPC requests, use the `grpc` middleware
41+
To enable additional gRPC functionality, use the `grpc` middleware
7042

7143
```php
7244
<?php
@@ -78,6 +50,8 @@ return [
7850
];
7951
```
8052

53+
> Note: Request tracking is automatically enabled via the RequestHandledListener. The TelescopeMiddleware is only needed for additional gRPC-specific functionality.
54+
8155
## View Dashboard
8256

8357
`http://127.0.0.1:9501/telescope`

docs/zh-cn/components/telescope.md

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -34,39 +34,11 @@ php bin/hyperf.php migrate
3434

3535
## 使用
3636

37-
> 监听器和中间件,二选一即可
37+
### 中间件(可选,仅用于gRPC)
3838

39-
### 请求监听器
39+
`config/autoload/middlewares.php`配置文件加上中间件
4040

41-
`config/autoload/listeners.php`配置文件添加监听器
42-
43-
```php
44-
<?php
45-
46-
return [
47-
FriendsOfHyperf\Telescope\Listener\RequestHandledListener::class,
48-
FriendsOfHyperf\Telescope\Listener\SetRequestLifecycleListener::class,
49-
];
50-
51-
```
52-
53-
### 中间件
54-
55-
`config/autoload/middlewares.php`配置文件加上全局中间件
56-
57-
如需记录http请求,请使用`http`中间件
58-
59-
```php
60-
<?php
61-
62-
return [
63-
'http' => [
64-
FriendsOfHyperf\Telescope\Middleware\TelescopeMiddleware::class,
65-
],
66-
];
67-
```
68-
69-
如需记录gRPC请求,请使用`grpc`中间件
41+
如需gRPC的额外功能,请使用`grpc`中间件
7042

7143
```php
7244
<?php
@@ -78,6 +50,8 @@ return [
7850
];
7951
```
8052

53+
> 注意: 请求跟踪功能已通过 RequestHandledListener 自动启用。TelescopeMiddleware 仅用于 gRPC 的额外功能。
54+
8155
## 查看仪表板
8256

8357
`http://127.0.0.1:9501/telescope`

docs/zh-hk/components/telescope.md

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -34,39 +34,11 @@ php bin/hyperf.php migrate
3434

3535
## 使用
3636

37-
> 監聽器和中間件,二選一即可
37+
### 中間件(可選,僅用於gRPC)
3838

39-
### 請求監聽器
39+
`config/autoload/middlewares.php`配置文件加上中間件
4040

41-
`config/autoload/listeners.php`配置文件添加監聽器
42-
43-
```php
44-
<?php
45-
46-
return [
47-
FriendsOfHyperf\Telescope\Listener\RequestHandledListener::class,
48-
FriendsOfHyperf\Telescope\Listener\SetRequestLifecycleListener::class,
49-
];
50-
51-
```
52-
53-
### 中間件
54-
55-
`config/autoload/middlewares.php`配置文件加上全局中間件
56-
57-
如需記錄http請求,請使用`http`中間件
58-
59-
```php
60-
<?php
61-
62-
return [
63-
'http' => [
64-
FriendsOfHyperf\Telescope\Middleware\TelescopeMiddleware::class,
65-
],
66-
];
67-
```
68-
69-
如需記錄gRPC請求,請使用`grpc`中間件
41+
如需gRPC的額外功能,請使用`grpc`中間件
7042

7143
```php
7244
<?php
@@ -78,6 +50,8 @@ return [
7850
];
7951
```
8052

53+
> 注意: 請求追蹤功能已通過 RequestHandledListener 自動啟用。TelescopeMiddleware 僅用於 gRPC 的額外功能。
54+
8155
## 查看儀表板
8256

8357
`http://127.0.0.1:9501/telescope`

docs/zh-tw/components/telescope.md

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -34,39 +34,11 @@ php bin/hyperf.php migrate
3434

3535
## 使用
3636

37-
> 監聽器和中介軟體,二選一即可
37+
### 中介軟體(可選,僅用於gRPC)
3838

39-
### 請求監聽器
39+
`config/autoload/middlewares.php`配置檔案加上中介軟體
4040

41-
`config/autoload/listeners.php`配置檔案新增監聽器
42-
43-
```php
44-
<?php
45-
46-
return [
47-
FriendsOfHyperf\Telescope\Listener\RequestHandledListener::class,
48-
FriendsOfHyperf\Telescope\Listener\SetRequestLifecycleListener::class,
49-
];
50-
51-
```
52-
53-
### 中介軟體
54-
55-
`config/autoload/middlewares.php`配置檔案加上全域性中介軟體
56-
57-
如需記錄http請求,請使用`http`中介軟體
58-
59-
```php
60-
<?php
61-
62-
return [
63-
'http' => [
64-
FriendsOfHyperf\Telescope\Middleware\TelescopeMiddleware::class,
65-
],
66-
];
67-
```
68-
69-
如需記錄gRPC請求,請使用`grpc`中介軟體
41+
如需gRPC的額外功能,請使用`grpc`中介軟體
7042

7143
```php
7244
<?php
@@ -78,6 +50,8 @@ return [
7850
];
7951
```
8052

53+
> 注意: 請求追蹤功能已透過 RequestHandledListener 自動啟用。TelescopeMiddleware 僅用於 gRPC 的額外功能。
54+
8155
## 檢視儀表板
8256

8357
`http://127.0.0.1:9501/telescope`

src/telescope/README.md

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,7 @@ php bin/hyperf.php vendor:publish friendsofhyperf/telescope
3939
php bin/hyperf.php migrate
4040
```
4141

42-
## Add Listener
43-
44-
```php
45-
<?php
46-
47-
// config/autoload/listeners.php
48-
49-
return [
50-
FriendsOfHyperf\Telescope\Listener\SetRequestLifecycleListener::class,
51-
FriendsOfHyperf\Telescope\Listener\RequestHandledListener::class,
52-
];
53-
54-
```
55-
56-
## Add Middleware
42+
## Add Middleware (Optional for gRPC)
5743

5844
```php
5945
<?php
@@ -68,7 +54,7 @@ return [
6854

6955
```
7056

71-
> TelescopeMiddleware or RequestHandledListener, you can choose one of them.
57+
> Note: Request tracking is automatically enabled via the RequestHandledListener. The TelescopeMiddleware is only needed for additional gRPC-specific functionality.
7258
7359
## Add env
7460

src/telescope/src/ConfigProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public function __invoke(): array
4848
Listener\FetchRecordingOnBootListener::class,
4949
Listener\RedisCommandExecutedListener::class,
5050
Listener\RegisterRoutesListener::class => -1,
51+
Listener\RequestHandledListener::class,
52+
Listener\SetRequestLifecycleListener::class,
5153
],
5254
'publish' => [
5355
[

0 commit comments

Comments
 (0)