Loading

链路追踪Sleuth入门

接下来通过之前的项目案例整合Sleuth,完成入门案例的编写

(1) 配置依赖

修改微服务工程引入Sleuth依赖
<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>

(2) 修改配置文件

修改application.yml添加日志级别
  logging:
    level:
      root: INFO
      org.springframework.web.servlet.DispatcherServlet: DEBUG
      org.springframework.cloud.sleuth: DEBUG
每个微服务都需要添加如上的配置。启动微服务,调用之后,我们可以在控制台观察到sleuth的日志输出:
service-order:

service-product:

api-gateway-server:

其中 72458585a353bd21 是TraceId,后面跟着的是SpanId,一次调用有一个全局的TraceId,将调用链路串起来。仔细分析每个微服务的日志,不难看出请求的具体过程。
查看日志文件并不是一个很好的方法,当微服务越来越多日志文件也会越来越多,通过Zipkin可以将日志聚合,并进行可视化展示和全文检索。
posted @ 2021-07-29 14:43  1640808365  阅读(90)  评论(0编辑  收藏  举报