用AI赚第一桶💰低成本搭建一套AI赚钱工具,源码可二开。 广告
## 调用链追踪 一个完整的微服务系统包含多个微服务单元,各个微服务子系统存在互相调用的情况,形成一个 **调用链**。一个客户端请求从发出到被响应 **经历了哪些组件**、**哪些微服务**、**请求总时长**、**每个组件所花时长** 等信息我们有必要了解和收集,以帮助我们定位性能瓶颈、进行性能调优,因此监控整个微服务架构的调用链十分有必要,本文将阐述如何使用 **Zipkin** 搭建微服务调用链追踪中心。 ## Mix Tracing Zipkin >[info] 需先安装 Zipkin V2 该组件基于 OpenTracing 规范设计。 使用 [composer](https://www.phpcomposer.com/) 安装: ``` composer require mix/tracing-zipkin ``` ## 依赖注入配置 - [manifest/beans/zipkin.php](https://github.com/mix-php/mix-micro-skeleton/blob/master/manifest/beans/zipkin.php) ## Mix Tracing 调用链的追踪是通过中间件的形式在 Server、Client 中传播,Mix Tracing 提供了 HttpServer、gRPC、JSON-RPC 的相关中间件,只需将这些中间件配置到对应的位置即可追踪。 使用 [composer](https://www.phpcomposer.com/) 安装: ``` composer require mix/tracing ``` - Http Route 配置 Tracing 中间件:[manifest/beans/route.php#L20](https://github.com/mix-php/mix-micro-skeleton/blob/master/manifest/beans/route.php#L20) - gRPC Client 配置 Tracing 中间件:[SayController.php#L56](https://github.com/mix-php/mix-micro-skeleton/blob/master/app/Api/Controllers/Greeter/SayController.php#L56) - gRPC Server 配置 Tracing 中间件:[manifest/beans/grpc.php#L25](https://github.com/mix-php/mix-micro-skeleton/blob/master/manifest/beans/grpc.php#L25) 追踪成功的请求会在响应 Header 中包含 X-B3-Traceid 头,可通过改 ID 在 zipkin 管理端中快速查看追踪信息。