多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
tracing 插件基于 Jaeger: open source, end-to-end distributed tracing。 # tracing-plugin 安装 conpose.json 增加以下配置。 ~~~ { "minimum-stability": "beta" } ~~~ ~~~ composer require esd/tracing-plugin ~~~ 在 Application 类中增加 configure 方法,注意导入命名空间。 ~~~ use ESD\Go\GoApplication; use ESD\Plugins\DBTracing\DBTracingPlugin; use ESD\Plugins\HttpClientTracing\HttpClientTracingPlugin; use ESD\Plugins\MethodTracing\MethodTracingPlugin; use ESD\Plugins\RequestTracing\RequestTracingPlugin; class Application extends GoApplication { public static function main() { $application = new GoApplication(); $application->addPlug(new RequestTracingPlugin()); $application->addPlug(new DBTracingPlugin()); $application->addPlug(new MethodTracingPlugin()); $application->addPlug(new HttpClientTracingPlugin()); $application->run(); } } ~~~ 在需要监测的类上增加TracingInterface接口的继承。GoController ,GoModel 的类默认已经继承,任何继承他们的类都不需要添加。 ~~~ <?php /** * Created by PhpStorm. * User: anythink * Date: 2019/6/7 * Time: 17:50 */ namespace app\Service; class GoodService implements TracingInterface { } ~~~ # 配置服务 启动如下docker 服务。 ~~~bash $ docker run -d --name jaeger \ -e COLLECTOR_ZIPKIN_HTTP_PORT=9411 \ -p 5775:5775/udp \ -p 6831:6831/udp \ -p 6832:6832/udp \ -p 5778:5778 \ -p 16686:16686 \ -p 14268:14268 \ -p 9411:9411 \ jaegertracing/all-in-one:1.12 ~~~ 配置ESD的tracing 配置 ~~~ tracing: enable: true host: 192.168.65.2 port: 9411 sampling_ratio: 1 ~~~ sampling_ratio 为采样率,1为100%, 会有10%的性能损耗,线上可以设置为 0.01 ,损耗可忽略不计。 # 查看追踪 打开地址 [http://localhost:16686/](http://localhost:16686/)。然后点击左侧 find traces。 ![](https://box.kancloud.cn/2c1ec4be276b87cb99d1e73afffbc6f0_1821x913.png) ![](https://box.kancloud.cn/1a88ea9ec582ac89244201d2b4e21478_1833x927.png) # 插件监测 tracing-plugin 支持监测 mysql redis saber easyroute 插件。 # 更多 [开放分布式追踪(OpenTracing)入门与 Jaeger 实现](https://yq.aliyun.com/articles/514488)