spring-cloud-sleuth-otel: New baggage not getting flushed in the current span with otel

I have created a spring-boot micro-service with spring-cloud-sleuth-otel. 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

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 16

Most upvoted comments

OK I’ll look into that ASAP

Hmm can you prepare a very simple scenario like the one in micrometer samples that would replicate the problem?

@marcingrzejszczak I have already prepared the scenario with the fewest files possible. I can not remove docker files because those are needed for otel-collector to run and also, there are only 3 Java files, aspect ,controller and service all of which contribute in reproducing this issue.