Trace context not available with WebFlux
See original GitHub issueBug report
The trace context is not always available with WebFlux.
- Spring Boot version: 2.1.0
- Spring Cloud version: Greenwich M3. Same issue with Greenwich M2. No issue with Greenwich M1
- Sample project: https://github.com/jumal/sleuth-webflux-no-trace-context-issue
Trying to access propagated extra fields fails due to the unavailability of the trace context in Webflux.
The following code, that used to work with Spring Cloud Finchley and Greenwich M1, does not work anymore with Spring Cloud Greenwich M2 and M3:
- application.properties
spring.sleuth.propagation-keys=X-Field2
- Test
webClient
.post().uri("/test")
.contentType(APPLICATION_JSON)
.accept(APPLICATION_JSON)
.header("X-Field2", "field2")
.body(just(entity), TestEntity.class)
.exchange();
- Handler
Mono<ServerResponse> save(ServerRequest request) {
return request.bodyToMono(TestEntity.class)
.map(TestEntity::setContext)
.flatMap(repository::save)
.flatMap(entity -> ok().build());
}
- TestEntity
TestEntity setContext() {
field2 = ExtraFieldPropagation.get("X-Field2");
return this;
}
ExtraFieldPropagation.get(“X-Field2”) returns null because the trace context is not available.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Implement trace-id with Spring Webflux - Stack Overflow
I'd like to generate unique traceId per request and pass it through all services. In Spring MVC it was fairly easy by using...
Read more >How to handle logs and tracing in Spring WebFlux and ...
In Spring Boot, if we call one service/module to another using Feign client we can see an X-B3-TraceId in the header which basically...
Read more >spring-cloud/spring-cloud-sleuth - Gitter
Hi, I'm having some issues propagating Sleuth tracing correctly with Reactor (Spring WebFlux). Base on this example: package com.example.demo import org.
Read more >Unobvious traps of Spring WebFlux | by Łukasz Kyć
We just had to create a custom WebFilter, which reads the Correlation ID from the HTTP request and sets it in the context...
Read more >Web on Reactive Stack - Spring
Spring WebFlux does not have built-in support to start or stop a server. ... getProperty("java.io.tmpdir")); Context rootContext = server.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Added sample project to reproduce the issue: https://github.com/jumal/sleuth-webflux-no-trace-context-issue
Ah thanks for the clarification @bsideup. I must have misunderstood you.