spring cloud Sleuth 使用笔记

本文详细介绍了Spring Cloud Sleuth的使用,包括traceId和spanId的生成机制,Sleuth与其他组件的集成,如dubbo、httpclient等,并探讨了HTTP请求中的头信息传播方式。此外,还讨论了非Spring Cloud Sleuth项目如何对接,并提供了Brave源码分析的相关资源。
摘要由CSDN通过智能技术生成

spring cloud Sleuth 使用笔记
git 源码:https://github.com/spring-cloud/spring-cloud-sleuth
1.traceId 和spanId生成机制
类brave.tracer:
在这里插入图片描述
在这里插入图片描述 brave.internal.Platform
在这里插入图片描述在这里插入图片描述在这里插入图片描述最终发现生成id机制是:
java.util.concurrent.ThreadLocalRandom.current().nextLong();
是一个long类型的非零随机数(64位二进制,-9223372036854775808 ~ 9223372036854775807之间的非零数值。)
向下游传播和MDC中都是被转成16位十六进制字符串(负正数以无符号处理,不足16位左边补0)。
关于ThreadLocalRandom,可以参考别人的博客《并发包中ThreadLocalRandom类原理剖析》:https://www.jianshu.com/p/9c2198586f9b
2.sleuth使用

<dependencyManagement> 
      <dependencies>
          <dependency>
              <groupId>org.springframework.cloud</groupId>
              <artifactId>spring-cloud-dependencies</artifactId>
              <version>${release.train.version}</version>
              <type>pom</type>
              <scope>import</scope>
          </dependency>
      </dependencies>
</dependencyManagement>

<dependency> 
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>

Spring Cloud Sleuth 2.0.0以后添加了很多组件的支持,比如dubbo,apache httpclient,kafka,rabbitmq等,具体更新的内容有:
Rewritten using Brave #829, migration guide https://github.com/spring-cloud/spring-cloud-sleuth/wiki/Spring-Cloud-Sleuth-2.0-Migration-Guide
Removed the sleuth-stream #555 and zipkin-stream #727 dependencies. Spans via messaging can be only sent to Zipkin via native Zipkin dependencies.
spring.zipkin.sender.type=kafka needs to explicitly be set to send spans over Kafka #985, #1013
Added WebClient.Builder support #779
Trace tags account for parametrized URL #802

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值