英文:
BaggageField value returns null after update
问题
以下是您提供的内容的中文翻译:
我有以下的Spring Cloud Sleuth配置:
application.yml 文件:
sleuth:
baggage:
remote-fields: userId
correlation-fields: userId
配置类:
@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();
}
}
当在控制器中更新BaggageField时,getValue() 方法始终返回 null,尽管我配置了相应的BaggageField以在更新时刷新(.flushOnupdate() 文档):
@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("设置BaggageField为 {}", userId);
this.userIdBaggageField.updateValue(userId);
log.info("BaggageField的值为 {}", this.userIdBaggageField.getValue());
}
}
日志:
设置BaggageField为 1234
BaggageField的值为 null
我可能错过了什么?谢谢。
英文:
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.
答案1
得分: 0
问题是由于配置的自定义传播器干扰默认的行李传播而引起的。
移除它会修复这个问题。
英文:
The issue was due to a configured custom propagator interfering with default baggage propagation.
Removing it fixes this issue.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论