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

Spring Boot集成Spring Sleuth与OpenTelemetry追踪时异常求助

解决Spring Sleuth + OpenTelemetry 版本依赖冲突问题

核心问题定位

NoSuchMethodError 完全是OpenTelemetry相关依赖版本不一致导致的——opentelemetry-exporter-otlp-trace:1.14.0 和 opentelemetry-exporter-otlp-common:1.16.0 版本不匹配,方法签名或类结构变化引发了方法找不到的错误。

具体解决步骤

1. 统一OpenTelemetry所有依赖版本

在dependencyManagement中通过BOM强制指定所有OpenTelemetry相关依赖的统一版本,彻底避免依赖传递带来的版本差异:

<dependencyManagement>
    <dependencies>
        <!-- 引入OpenTelemetry BOM统一管理所有OTel依赖版本 -->
        <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-bom</artifactId>
            <version>1.16.0</version> <!-- 选择与otlp-common一致的版本 -->
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <!-- 引入Spring Cloud Sleuth OTEL的依赖管理包,确保与Spring生态兼容 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-sleuth-otel-dependencies</artifactId>
            <version>1.1.0</version> <!-- 根据你的Spring Cloud版本选择兼容版本 -->
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

2. 精简并规范业务依赖

检查pom.xml,移除手动引入的冗余OTLP相关依赖,只保留必要组件,版本由BOM自动管理:

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-sleuth</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-sleuth-otel-autoconfigure</artifactId>
    </dependency>
    <dependency>
        <groupId>io.opentelemetry</groupId>
        <artifactId>opentelemetry-exporter-otlp-trace</artifactId>
        <!-- 无需手动指定版本,由BOM统一管控 -->
    </dependency>
    <dependency>
        <groupId>io.grpc</groupId>
        <artifactId>grpc-okhttp</artifactId>
    </dependency>
</dependencies>

3. 验证依赖树一致性

执行Maven命令检查依赖树,确认所有OpenTelemetry相关依赖版本统一:

mvn dependency:tree | grep opentelemetry

确保输出的所有opentelemetry-前缀依赖版本均为你指定的统一版本(如1.16.0)。

4. 清理构建缓存

清理Maven本地仓库的冲突缓存,避免旧版本依赖干扰:

mvn clean install -U

-U参数会强制更新快照依赖,确保拉取最新的统一版本组件。

5. 确认版本兼容性

Spring Cloud Sleuth OTEL与OpenTelemetry版本有严格兼容要求,比如:

  • Spring Cloud Sleuth OTEL 1.1.x 适配 OpenTelemetry 1.15.x-1.17.x
  • Spring Boot 2.7.x 对应Spring Cloud 2021.0.x(Jubilee),搭配Sleuth OTEL 1.1.x是合理选择

若版本不匹配,同样会引发方法缺失问题,务必对应官方兼容矩阵调整。


内容的提问来源于stack exchange,提问作者Udeshika Sewwandi

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 12:55:36