-
Notifications
You must be signed in to change notification settings - Fork 784
Closed
Description
Bug 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.