最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

spring boot - Baggage field isn't propagated - Stack Overflow

programmeradmin3浏览0评论

I have the following demo application Spring Boot 3.4.2:

@SpringBootApplication
@RestController
public class BaggageTestApplication {

    public static void main(String[] args) {
        SpringApplication.run(BaggageTestApplication.class, args);
    }

    private static final Log LOGGER = LogFactory.getLog(BaggageTestApplication.class);

    private final WebClient webClient;
    private final Tracer tracer;

    public BaggageTestApplication(WebClient webClient, Tracer tracer) {
        this.webClient = webClient;
        this.tracer = tracer;
    }

    @RequestMapping("/")
    ResponseEntity<Void> home(@RequestHeader Map<String, String> headers) {
        headers.forEach((key, value) -> LOGGER.info(key + ": " + value));
        return ResponseEntity.ok().build();
    }

    @EventListener
    public void onApplicationEvent(ApplicationReadyEvent event) {
        try (BaggageInScope scope = this.tracer.createBaggageInScope("baggage1", "value1")) {
            webClient.get()
                    .retrieve()
                    .toBodilessEntity()
                    .block();
        }
    }
}

@Configuration
class WebclientConfiguration {
    @Bean
    public WebClient webClient(WebClient.Builder builder) {
        return builder.
                baseUrl("http://localhost:8080")
                .build();
    }
}

and application.yml:

spring:
  application:
    name: baggage-test
management:
  tracing:
    sampling:
      probability: 1.0
    baggage:
      remote-fields: baggage1
      enabled: true
    enabled: true

I expected the new custom header, baggage1, to be automatically added during the webClient request, but only the following were available:

accept-encoding: gzip
user-agent: ReactorNetty/1.2.2
host: localhost:8080
accept: */*
traceparent: 00-67b20fe3ed21c20685f6746f77ef8e74-85f6746f77ef8e74-01
content-length: 0

For some reason, the baggage field wasn't propagated at all.

发布评论

评论列表(0)

  1. 暂无评论