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

迁移至SpringBoot 3后Spring Cloud Stream应用追踪丢失求助

Spring Cloud Stream迁移至Spring Boot 3后追踪丢失问题

将Spring Cloud Stream应用迁移到Spring Boot 3后,出现了追踪信息丢失的问题。应用仅包含以下代码类:

package com.example.micrometer;

import io.micrometer.observation.ObservationRegistry;
import io.micrometer.tracing.Tracer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.messaging.Message;
import reactor.core.publisher.Flux;

import java.util.function.Consumer;

@SpringBootApplication
public class StreamReactiveConsumerApplication implements CommandLineRunner {

    private static final Logger log = LoggerFactory.getLogger(StreamReactiveConsumerApplication.class);

    public static void main(String... args) {
        new SpringApplicationBuilder(StreamReactiveConsumerApplication.class).web(WebApplicationType.NONE).run(args);
    }

    @Override
    public void run(String... args) throws Exception {
        log.warn("Remember about calling <.subscribe()> at the end of your Consumer<Flux> bean!");
        log.warn("Remember about finishing the span manually before calling subscribe!");
    }

    @Bean
    Consumer<Flux<Message<String>>> channel(Tracer tracer, ObservationRegistry observationRegistry) {
        return flux -> flux.doOnNext(msg -> log.info("<ACCEPTANCE_TEST> <TRACE:{}> Hello from consumer",
                tracer.currentSpan().context().traceId()))
                .subscribe();
    }

}

应用配置文件如下:

spring:
  application:
    name: stream-reactive-consumer
  cloud:
    stream:
      bindings:
        channel-in-0.destination: myinput
      kafka:
        streams:
          binder:
            functions:
              kafkaStreamCountWords:
                configuration:
                  client.id: client-id-kafkaStreamCount

# For tests
logging:
  pattern:
    console: '%d{yyyy-MM-dd HH:mm:ss} [${spring.application.name:},%X{traceId:-},%X{spanId:-}] %logger{36} : %msg%n'

已在配置中添加了包含traceId/spanId的日志格式,并且引入了context-propagation库,也参考了观测和追踪迁移相关文档,但追踪信息仍然丢失,请求协助解决。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 04:50:28