[英]Sleuth traceId and spanId are not propagated to parallelStream worker threads
I have integrated Sleuth to my Spring Boot project in order to have a better traceability.我已将 Sleuth 集成到我的 Spring 引导项目中,以便获得更好的可追溯性。 It logs perfectly traceId and spanId.
它完美地记录了 traceId 和 spanId。 However, these fields are not added to logs generated in some operations performed using parallelStream.
但是,这些字段不会添加到使用 parallelStream 执行的某些操作中生成的日志中。
Sleuth doc suggests to use CompletableFuture instead : Sleuth doc 建议改用 CompletableFuture :
Sleuth does not work with parallelStream() out of the box.
Sleuth 不适用于开箱即用的 parallelStream()。 If you want to have the tracing information propagated through the stream, you have to use the approach with supplyAsync(...), as shown earlier
如果您想通过 stream 传播跟踪信息,则必须使用带有 supplyAsync(...) 的方法,如前所示
But it says that parallelStream does not work "out of the box".但它说 parallelStream 不能“开箱即用”。 So, is there any workaround to use parallelStream?
那么,有什么解决方法可以使用 parallelStream 吗?
Thanks for any help or comment on this感谢您对此的任何帮助或评论
The closest you can do is to call a completable future你能做的最接近的就是称一个完整的未来
CompletableFuture completableFuture = CompletableFuture.supplyAsync(() -> {
ingredientsCollector.collectIngredients(order, processId).stream()
.filter(ingredient -> ingredient != null)
.forEach((Ingredient ingredient) -> {
log.info("Adding an ingredient [{}] for order [{}] , processId [{}]", ingredient);
ingredientWarehouse.addIngredient(ingredient);
});
return null;
}, new TraceableExecutorService(this.beanFactory, Executors.newFixedThreadPool(5), "fetchIngredients"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.