Skip to content

Trace context not available with WebFlux #1143

@jumal

Description

@jumal

Bug report

The trace context is not always available with WebFlux.

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.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions