spring-cloud/spring-cloud-sleuth

New baggage not getting flushed in the current span with otel

ff-sdesai opened this issue · 2 comments

I have created a spring-boot micro-service with spring-cloud-sleuth. I have also configured a open-telemetry-collector to forward the logs to datadog. The otel-collector is running in a docker container along with the micro-service.
I am trying to add a new baggage in an aspect (com.uplight.aspect.TestApplicationAspect.java). However, the baggage gets added starting from next new span only (Created using @NewSpan in com.uplight.service.TestServiceImpl).
This issue can be reproduced using a POC with very few files and is uploaded at https://github.com/ff-sdesai/distributed-tracing-spring. The readme.md has the steps to run the application. You will need to enter a valid datadog API key in the .env file.I will not be able to share the key since the key is specific to my organization. But even if you don't enter the key, you will be able to see on the otel-collector console that the span named HTTP GET does not print the newly added baggage.

I also found out that this can be achieved in Brave by creating a bean of ScopeDecorator in following way

 @Bean
     ScopeDecorator mdcScopeDecorator() {
     return MDCScopeDecorator.newBuilder().clear().add( SingleCorrelationField.newBuilder( countryCodeField() ).flushOnUpdate().build() ).build();
     }

However, I could not find a way to achieve this when not using brave

Are you using spring cloud sleuth otel? If that's the case please file an issue in that repo. Also please ensure that you're using the latest versions of the project

@marcingrzejszczak Yes, I am using spring-cloud-sleuth-otel and I am already using latest versions of all artifacts. Will file an issue in that repo. Thanks.