spring-cloud-sleuth: Regression in Webflux test when explicitely providing tracing headers

Describe the bug Re-opening spring-projects/spring-cloud-sleuth#1507 because it looks like there is a regression linked to this bug.

Reminder of the encountered issue:

Once using Sleuth and injecting Tracing headers in a WebTestClient I was able to retrieve them in Reactor’s context later on like this :

// Test
webTestClient.get()
    .uri("/api/tracing")
    .header("X-B3-TraceId", "463ac35c9f6413ad48485a3953bb6124")
    .header("X-B3-SpanId", "a2fb4a1d1a96d312")

// Controller
@GetMapping
    fun spanId(): Mono<String> {
        return Mono.subscriberContext()
                .filter { it.hasKey(Span::class.java) }
                .map { it[Span::class.java].context() }
                .map { it.spanIdString() }
    }

When comparing spanId and parentId present in the org.springframework.cloud.sleuth.TraceContext object, it appears that values are different than the spanId and parentId set in the headers.

Spring libraries versions used to reproduce this issue:

  • spring Boot 2.4.2.RELEASE
  • spring Framework 5.3.3.RELEASE
  • spring-test 5.3.3.RELEASE
  • spring-cloud-sleuth; 3.0.1

Sample Sample available here The branch 2021 contains latest changes to reproduce the issue with latest libraries (project forked from the initial reproducer) The issue can be reproduced by executing the test com.spring.reproducer.spring.test.sleuth.reproducer.TracingResourceTest

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 25 (12 by maintainers)

Most upvoted comments

I know what the problem is. Brave has the notion of Propagation and Propagation.Factory. When I introduced the composite of propagation types I have not overriden the Propagation.Factory methods. That means that what you see that happens is that supportJoin is equal to false. The trace headers are properly parsed but since support join is disabled it creates a new child span.

As a workaround what you can do is create your own bean like this

@Bean
	BaggagePropagation.FactoryBuilder myBaggagePropagationFactoryBuilder() {
		return BaggagePropagation.newFactoryBuilder(B3Propagation.newFactoryBuilder().injectFormat(B3Propagation.Format.SINGLE_NO_PARENT).build());
	}

and then you’ll override the faulty composite one that I’ll try to fix asap.

@marcingrzejszczak You can find the converted reproducer at the following location : here The test class to execute is TracingResourceTest.java

Hello @marcingrzejszczak, I’m going to take a look to convert it today in java/maven on a separate brach

X-B3-TraceId and X-B3-SpanId must be valid longs. If they are not then AFAIR we’re generating new ones