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,自定义属性也能正常显示在父级请求遥测中。
疑问点
- 能否强制
ServerHttpObservationFilter生成新的span,而非复用traceparent中的父ID?这是否属于应用的异常行为? - 在控制器中尝试多种方式创建新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
相关产品推荐
相关产品推荐

