SpringCloudAlibaba-整合sleuth和zipkin(六)

目录地址:

SpringCloudAlibaba整合-CSDN博客

一、整合sleuth

1.引入依赖

在需要追踪的微服务中引入依赖,user、order、product

XML 复制代码
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>

2.启动微服务;访问服务接口;可以看到order的控制台信息

绿色部分INFO,就是链路信息,参数:

参数一:微服务名称,spring.application.name 的值

参数二:表示 本次请求的链路追踪 id(Trace ID),本次请求涉及多个下游服务,链路追踪 id 相同,表示这些都是同一次追踪

参数三:表示 当前服务本次链路追踪的 id(Span ID),本次请求涉及多个下游服务,每个微服务的 Span ID 都不相同,代表不同的服务。

二、整合zipkin

1.安装并启动zipkin,可以自己下载,这里使用docker版

bash 复制代码
docker pull openzipkin/zipkin

docker run --name zipkin -p 9411:9411 openzipkin/zipkin -d

2.在3个微服务模块添加依赖

XML 复制代码
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-zipkin</artifactId>
     <!--zipkin 是第三方的,版本和 spring cloud 不同步,所以要指定版本-->
     <version>2.2.8.RELEASE</version>    
</dependency>

3.添加配置

XML 复制代码
spring:
  zipkin:
    # 配置 zipkin 服务所在地址
    base-url: http://localhost:9411
    # 不开启服务发现
    discovery-client-enabled: false
    sender:
      type: web
  sleuth:
    sampler:
      # 配置 sleuth 链路追踪采样 百分比,1:百分百,0.1:百分之十。采样比例过高影响性能
      probability: 0.1

4.启动微服务,访问order的接口,查看zipkin页面,可以点进去看详情

访问之后,过一会才能看到信息

5.zipkin的持久化

参考:https://cloud.tencent.com/developer/article/2318336

相关推荐
人间打气筒(Ada)3 天前
「码动四季·开源同行」go实战案例:如何在微服务中集成 Zipkin 组件?
微服务·golang·开源·grpc·zipkin·http调用
leo_messi944 天前
2026版商城项目(二)-- 压力测试&缓存
java·缓存·压力测试·springcloud
總鑽風5 天前
springcloud2023_alibaba_sso单点登录_授权码模式(已跑通)
springcloud·单点登录·sso·授权码模式
總鑽風6 天前
springcloudalibaba2021-SSO 单点登录_密码模式
springcloud·alibaba·sso
奥升新能源平台9 天前
奥升充电最小化高可用机房部署方案
运维·安全·开源·能源·springcloud
leo_messi9412 天前
2026版商城项目(一)
java·elasticsearch·k8s·springcloud
没有bug.的程序员12 天前
S 级 SaaS 平台的物理雪崩:Spring Cloud Gateway 多租户动态路由与 UserID 极限分片
java·gateway·springboot·saas·springcloud·多租户、·userid
Thomas.Sir23 天前
SpringBoot 3 集成 Sleuth + zipkin 实现微服务链路追踪
spring·spring cloud·微服务·sleuth·zipkin·日志追踪
Dragon Wu1 个月前
SpringCache 缓存使用总结
spring boot·后端·spring·缓存·springcloud
七夜zippoe1 个月前
微服务链路追踪实战:SkyWalking vs Zipkin 架构深度解析与性能优化指南
java·开发语言·微服务·springcloud·sleuth·zipkin