Spring Cloud SOFA 集成了蚂蚁集团开源的分布式链路追踪系统 SofaTracer。SofaTracer 遵循 OpenTracing 规范,通过一个全局的 TraceId 将分布在各个服务节点上的同一次请求串联起来,并支持主动上报的方式提供给服务端进行展示,达到透视化网络调用的目的。
Spring Cloud Sofa Tracer 与 Sofa 的实时监控系统 RMS 无缝整合,只要在项目中接入 Spring Cloud Sofa Tracer,并部署 RMS agent,即可通过 RMS 查看到服务的完整链路及各阶段耗时,用于问题定位,性能分析等场合。也可通过配置将链路信息主动上报给 RMS,或开源的 Zipkin 进行展示。
有关 SofaTracer 的更多信息,请参见什么是 SOFATracer。
配置链路追踪
在项目工程中添加 Spring Cloud Sofa Tracer 依赖。
不要配置版本,版本由 dependencyManagement 控制。本例中演示通过 SpringMVC 发布 Rest 服务,通过 OpenFeign 和 RestTemplate 调用服务,因此加入了相关依赖。
<dependency> <groupId>com.alipay.cloud</groupId> <artifactId>spring-cloud-starter-sofa-tracer</artifactId> </dependency> <!-- 引入服务框架 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency> <!-- 引入负载均衡 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-loadbalancer</artifactId> </dependency>
启动测试应用,触发服务调用。
完成后,您可在
{user.dir}/logs/tracelog
目录中查看到 tracelog。本例中将会产生以下文件:feign-digest.log feign-stat.log resttemplate-digest.log resttemplate-stat.log spring-mvc-digest.log spring-mvc-stat.log static-info.log tracer-self.log
相关文件含义和格式说明请参见日志说明。
该文章对您有帮助吗?