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

SpringBoot Webflux复用traceparent的spanId及自定义Span不生效求助

Spring Boot Webflux 追踪链路问题

环境信息

  • Spring Boot 3.0.8(Webflux 架构)
  • 监控方案:Micrometer + OpenTelemetry
  • 自动埋点工具:Azure Application Insight Agent v3.4.16

核心问题

当收到携带traceparent头(示例:00-bf04bc4e217f54815d9b8cbafc2838d6-be853f762ca0c929-01)的HTTP请求时,应用内所有追踪逻辑均复用该头中的spanId(be853f762ca0c929),未生成新的spanId。该ID对应AppInsight中的依赖遥测类型,是当前请求在整个追踪链中的父级节点。

由此导致的问题:无法为该span设置自定义属性并在AppInsight的依赖/请求遥测中展示。但如果请求不携带traceparent头,应用会正常生成新的spanId,自定义属性也能正常显示在父级请求遥测中。

疑问点

  1. 能否强制ServerHttpObservationFilter生成新的span,而非复用traceparent中的父ID?这是否属于应用的异常行为?
  2. 在控制器中尝试多种方式创建新span(OpenTelemetry Tracer、Micrometer Tracer、Observation、@NewSpan注解),但新生成的spanId并未在日志中体现,是否遗漏了关键配置?

已尝试的新span创建方式

使用Observation API

// observationRegistry已自动注入
return Observation.createNotStarted("example", observationRegistry) 
                .contextualName("example") 
                .lowCardinalityKeyValue("operation","example") 
                .observe(() -> doSomething())

使用OpenTelemetry Tracer

// tracer已自动注入(io.opentelemetry.api.trace.Tracer)
Span span = tracer.spanBuilder(incomingPath.value())
                .startSpan();
span.makeCurrent();
return this.webclient.get()
          // ... 业务请求逻辑
       .doFinally(signaltype -> {
             span.stop();
       });

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.08 14:09:56