question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trace context not available with WebFlux

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jumalcommented, Nov 24, 2018

Added sample project to reproduce the issue: https://github.com/jumal/sleuth-webflux-no-trace-context-issue

0reactions
marcingrzejszczakcommented, Jan 28, 2019

Ah thanks for the clarification @bsideup. I must have misunderstood you.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found