├── .gitattributes ├── LICENSE ├── README.md ├── composer.json └── src ├── Aspect └── CoroutineHandlerAspect.php ├── ConfigProvider.php └── Middleware ├── HookMallocMiddleware.php └── HttpServerMiddleware.php /.gitattributes: -------------------------------------------------------------------------------- 1 | /tests export-ignore 2 | /.github export-ignore 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Hyperf 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Swoole Tracker 2 | 3 | [Swoole Tracker](https://business.swoole.com/tracker/index)作为`Swoole`官方出品的一整套企业级`PHP`和`Swoole`分析调试工具,更专一、更专业。 4 | 5 | * 时刻掌握应用架构模型 6 | 7 | > 自动发现应用依赖拓扑结构和展示,时刻掌握应用的架构模型 8 | 9 | * 分布式跨应用链路追踪 10 | 11 | > 支持无侵入的分布式跨应用链路追踪,让每个请求一目了然,全面支持协程/非协程环境,数据实时可视化 12 | 13 | * 全面分析报告服务状况 14 | 15 | > 各种维度统计服务上报的调用信息, 比如总流量、平均耗时、超时率等,并全面分析报告服务状况 16 | 17 | * 拥有强大的调试工具链 18 | 19 | > 本系统支持远程调试,可在系统后台远程开启检测内存泄漏、阻塞检测和代码性能分析 20 | 21 | * 同时支持FPM和Swoole 22 | 23 | > 完美支持PHP-FPM环境,不仅限于在Swoole中使用 24 | 25 | * 完善的系统监控 26 | 27 | > 支持完善的系统监控,零成本部署,监控机器的CPU、内存、网络、磁盘等资源,可以很方便的集成到现有报警系统 28 | 29 | * 零成本接入系统 30 | 31 | > 本系统的客户端提供脚本可一键部署,服务端可在Docker环境中运行,简单快捷 32 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hyperf/swoole-tracker", 3 | "description": "A swoole tracker library for Hyperf.", 4 | "license": "MIT", 5 | "keywords": [ 6 | "php", 7 | "swoole", 8 | "hyperf", 9 | "swoole-tracker" 10 | ], 11 | "homepage": "https://hyperf.io", 12 | "support": { 13 | "docs": "https://hyperf.wiki", 14 | "issues": "https://github.com/hyperf/hyperf/issues", 15 | "pull-request": "https://github.com/hyperf/hyperf/pulls", 16 | "source": "https://github.com/hyperf/hyperf" 17 | }, 18 | "require": { 19 | "php": ">=8.0", 20 | "hyperf/contract": "~3.0.0", 21 | "hyperf/support": "~3.0.0", 22 | "hyperf/utils": "~3.0.0", 23 | "psr/container": "^1.0|^2.0", 24 | "psr/http-server-middleware": "^1.0" 25 | }, 26 | "autoload": { 27 | "psr-4": { 28 | "Hyperf\\SwooleTracker\\": "src/" 29 | } 30 | }, 31 | "autoload-dev": { 32 | "psr-4": { 33 | } 34 | }, 35 | "config": { 36 | "sort-packages": true 37 | }, 38 | "extra": { 39 | "branch-alias": { 40 | "dev-master": "3.0-dev" 41 | }, 42 | "hyperf": { 43 | "config": "Hyperf\\SwooleTracker\\ConfigProvider" 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Aspect/CoroutineHandlerAspect.php: -------------------------------------------------------------------------------- 1 | getArguments()[0] ?? null) { 37 | if ($client instanceof Client && function_exists('getSwooleTrackerTraceId') && function_exists('getSwooleTrackerSpanId')) { 38 | $client->setHeaders(array_merge( 39 | [ 40 | 'x-swoole-traceid' => getSwooleTrackerTraceId(), 41 | 'x-swoole-spanid' => getSwooleTrackerSpanId(), 42 | ], 43 | $client->requestHeaders 44 | )); 45 | } 46 | } 47 | return $proceedingJoinPoint->process(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/ConfigProvider.php: -------------------------------------------------------------------------------- 1 | handle($request); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Middleware/HttpServerMiddleware.php: -------------------------------------------------------------------------------- 1 | name = $config->get('app_name', 'hyperf-skeleton'); 30 | } 31 | 32 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface 33 | { 34 | if (class_exists(Stats::class)) { 35 | $path = $request->getUri()->getPath(); 36 | $ip = Network::ip(); 37 | $traceId = $request->getHeaderLine('x-swoole-traceid') ?: ''; 38 | $spanId = $request->getHeaderLine('x-swoole-spanid') ?: ''; 39 | 40 | $tick = Stats::beforeExecRpc($path, $this->name, $ip, $traceId, $spanId); 41 | try { 42 | $response = $handler->handle($request); 43 | Stats::afterExecRpc($tick, true, $response->getStatusCode()); 44 | } catch (Throwable $exception) { 45 | Stats::afterExecRpc($tick, false, $exception->getCode()); 46 | throw $exception; 47 | } 48 | } else { 49 | $response = $handler->handle($request); 50 | } 51 | 52 | return $response; 53 | } 54 | } 55 | --------------------------------------------------------------------------------