I have the following Spring Cloud Sleuth configuration:
application.yml
file:
sleuth:
baggage:
remote-fields: userId
correlation-fields: userId
Configuration class:
@Configuration
public class SleuthConfiguration {
@Bean
public BaggageField userIdBaggageField() {
return BaggageField.create("userId");
}
@Bean
public CurrentTraceContext.ScopeDecorator mdcScopeDecorator() {
return MDCScopeDecorator.newBuilder()
.clear()
.add(CorrelationScopeConfig.SingleCorrelationField
.newBuilder(userIdBaggageField())
.flushOnUpdate()
.build())
.build();
}
}
When updating the BaggageField in the controller, the getValue()
method always returns null, although I configured the corresponding BaggageField to flush on update (.flushOnupdate()
documentation):
@RestController
@Slf4j
static class SampleController {
private final BaggageField userIdBaggageField;
SampleController(BaggageField userIdBaggageField) {
this.userIdBaggageField = userIdBaggageField;
}
@GetMapping("/sample")
public void periodes(@RequestParam String userId) {
log.info("Setting BaggageField to {}", userId);
this.userIdBaggageField.updateValue(userId);
log.info("BaggageField value {}", this.userIdBaggageField.getValue());
}
}
Logs:
Setting BaggageField to 1234
BaggageField value null
What did I possibly miss?
Thanks.
The issue was due to a configured custom propagator interfering with default baggage propagation.
Removing it fixes this issue.