Skip to content

Headers not always propagated to MDC (with sample) #2098

@anderius

Description

@anderius

I want to read header values, and have them available on MDC. One single request works, but not when a test does many requests after each other.

Complete project that reproduces the error every time (on my computer, Java 17). Most often after only 6-7 iterations:

https://github.com/anderius/spring-sleuth-problem-demo

Excerpt from the sample:

@RestController
@SpringBootApplication
class DemoApplication {

    @Bean
    fun sleuthHttpServerRequestParser() = HttpRequestParser { request, context, _ ->
        request.header("customHeader")
            ?.let { BaggageField.create("customField").updateValue(context, it) }
    }

    @Bean
    fun spanHandler(): SpanHandler = SpanHandler.NOOP

    @GetMapping("/mdc")
    fun getMdc(): Map<String, String> = MDC.getCopyOfContextMap()
}

This issue might be related to #2064.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions