简体   繁体   English

Sleuth traceId 和 spanId 不会传播到 parallelStream 工作线程

[英]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.

相关问题 在 Sleuth 的日志中看不到 traceId 和 spanId - Can't see traceId and spanId in log for Sleuth 侦探日志traceId未传播到另一个服务 - Sleuth log traceId not propagated to another service 哪个记录 X-B3-SpanId 或 SpanId? X-B3-TraceId 还是 TraceId? (春天的侦探) - Which to log X-B3-SpanId or SpanId? X-B3-TraceId or TraceId? (Spring sleuth) Spring 云侦探 3.0.1 使用 logback 在日志中生成 traceid 和 spanid - Spring cloud sleuth 3.0.1 generate traceid & spanid in logs using logback Sleuth 不会在 Spring Boot 应用程序中打印 spanId、traceId - Sleuth doesnt print spanId,traceId in spring boot application 在使用带有新关键字的 resttemplate 进行 API 调用时,无法将 Sleuth traceid 和 spanid 传递给下游服务 - Not able to pass Sleuth traceid and spanid to downstream services while making API calls using resttemplate with new keyword 在sleuth中添加新标签,比如客户端ip地址,我想在日志中添加客户端ip地址,当然是用traceId,spanId - what should I do to add new tags in sleuth, such as client ip address, I want to add the client ip address in logs, of course, with traceId, spanId traceId 和 spanId 在整个记录器中都是一样的 - traceId and spanId are coming as same throughout the loggers 迁移到 Spring Boot 3 后 TraceId 和 SpanId 不可用 - TraceId and SpanId not available after migrating to Spring Boot 3 如何在 SQS 中发送和使用 sleuth traceId - How to send and consume sleuth traceId in SQS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM