You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot 3与Spring Boot 2服务间Trace ID不一致问题求助

Spring Boot 3与Spring Boot 2服务交互Trace ID不一致问题解决

发送端为Spring Boot 3,接收端为Spring Boot 2,跨版本服务交互时出现Trace ID仅前8位匹配、后半段不一致的现象(示例:668bf86dfd1f566257411febfd3e6a37 -> 668bf86d5a467c34d608bc9381400526)。

当前配置

Spring Boot 3 端配置

management:
  tracing:
    enabled: true
    sampling:
      probability: 1.0
    propagation:
      type: b3

Spring Boot 2 端配置

spring:
  sleuth:
    trace-id128: true
    supports-join: false
    propagation:
      type: b3, w3c

问题原因

Spring Boot 3 使用Micrometer Tracing替代了Spring Boot 2中的Spring Cloud Sleuth,两者在B3协议的128位Trace ID处理上存在默认行为差异:

  • Spring Boot 3的Micrometer Tracing默认B3传播可能仅传输Trace ID的部分字节,或使用与Sleuth不兼容的单头格式
  • Spring Boot 2的Sleuth开启128位Trace ID后,若接收到不完整的Trace ID,会自动补全随机后半段,导致ID不一致

解决方案

1. 调整Spring Boot 3端配置

将B3传播设置为与Sleuth对齐的多头格式,确保传输完整128位Trace ID:

management:
  tracing:
    enabled: true
    sampling:
      probability: 1.0
    propagation:
      type: b3
    b3:
      multi-header: true # 使用X-B3-TraceId、X-B3-SpanId等多头格式,匹配Sleuth默认行为

若偏好单头B3格式,需强制开启128位Trace ID传输:

management:
  tracing:
    enabled: true
    sampling:
      probability: 1.0
    propagation:
      type: b3
    b3:
      single-header: true
      include-128bit-trace-id: true # 单头格式下强制包含完整128位Trace ID

2. 调整Spring Boot 2端配置

优先使用B3传播,禁用接收外部Trace ID时自动生成新ID的行为:

spring:
  sleuth:
    trace-id128: true
    supports-join: false
    propagation:
      type: b3 # 移除w3c,避免多传播格式冲突
    generator:
      enabled: false # 接收到合法Trace ID时,不生成新ID

验证步骤

  • 检查请求头中是否存在完整的32位十六进制X-B3-TraceId
  • 确认Spring Boot 2端接收到的X-B3-TraceId与发送端完全一致
  • 跨服务调用后验证两端日志中的Trace ID完全匹配

内容的提问来源于stack exchange,提问作者Maria Bortsova

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 12:34:49