spring-cloud-sleuth-otel
spring-cloud-sleuth-otel copied to clipboard
Unable to add multiple baggage fields in HttpRequestParser
Describe the bug
When calling tracer.createBaggage multiple times in HttpRequestParser, only the last field is added. The previously added fields are gone.
Sample https://github.com/jarlehansen/spring-sleuth-baggage
HttpRequestParser
@Bean(HttpServerRequestParser.NAME)
fun sleuthHttpServerRequestParser(tracer: Tracer): HttpRequestParser {
return HttpRequestParser { _, _, _ ->
tracer.createBaggage("1", "1")
tracer.createBaggage("2", "2")
tracer.createBaggage("3", "3")
}
}
RestController
@GetMapping
fun get() = tracer.allBaggage
Response
{"3":"3"}
In the TestController-file this problem is shown. Run the application and go to http://localhost:8080, it will print all added baggage fields. Even though 3 fields are added, only the last is returned from the endpoint.
Thanks! Can you please rewrite the samples to Java?
Here is the java example: https://github.com/jarlehansen/spring-sleuth-baggage/tree/java
Any updates on this?
I will look into that asap, currently didn't have time
I did some debugging on this, and it seems like when the code is running inside the HttpRequestParser the span is invalid (traceid 0000000...). And therefore is the baggage not added. No idea why the span is invalid though.
Could it be that the HttpRequestParser is loaded before the span is started?
This works sort of: tracer.createBaggage(...).set(context, ...);
Where the context is added to the set method. However, I now get this exception:
java.lang.NullPointerException: Cannot invoke "org.springframework.cloud.sleuth.http.HttpServerRequest.header(String)" because "httpServerRequest" is null
For some reason it is always on the content-length header, not sure if that is a coincidence or not?
I have updated the java example here with the same issue, and also here it happens for the content-length header.
https://github.com/jarlehansen/spring-sleuth-baggage/tree/java-nullpointer
Sleuth reached the end of its OSS support timeline. We encourage to migrate to Micrometer Tracing.