Headers not always propagated to MDC (with sample)
See original GitHub issueI 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 https://github.com/spring-cloud/spring-cloud-sleuth/issues/2064.
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
WebClient MDC data not propagated · Issue #4089 - GitHub
A workaround for this is to manually propagate the MDC data using context. E.g. In your filter do something like this: String ws...
Read more >How does Spring Cloud Sleuth propagate the MDC context in ...
I need to do something similar to with other parars from some request headers so I created that puts it into the MDC...
Read more >5. Propagation - Spring Cloud
The most common propagation approach is to copy a trace context from a client by sending an RPC request to a server receiving...
Read more >Passing HTTP headers to another microservice and put them ...
In a microservice architecture, it is common to pass a custom HTTP header, let's say: “Correlation-ID”, from one service to another.
Read more >Context Propagation in Quarkus
Many Quarkus extensions require those contextual objects to operate properly: RESTEasy Reactive, ArC and Transaction for example.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@marcingrzejszczak Thank you for looking into this!
That means Spring Cloud Sleuth should not be used for any headers other than the ones used for sampling/tracing, unless we sample everything.
I had the idea the sampling was only how much was sent to zipkin (or similar), but it is also how much is instrumentated.
@marcingrzejszczak Maven and Java is ready! 😃
Project is same place: https://github.com/anderius/spring-sleuth-problem-demo
The setup in java: