dubbo
dubbo copied to clipboard
Observability tasks: trace delivery across threads(跨线程时的trace数据传递)
- [ ] I have searched the issues of this repository and believe that this is not a duplicate.
Describe the proposal
En:Generally, in Java, traceid and spanid are passed through the thread context, but in the case of multi-threading, there will be multiple thread contexts. At this time, the chain will be lost when the same request reaches the child thread. At this time, we need to copy the link data from one thread to the context of another thread. If you don’t know how to copy, you can consider how to share data between threads, such as using shared variables such as member variables.
中文:一般在Java中traceid和spanid我们都是通过线程上下文来传递的但是出现了多线程的情况下就会有多个线程上下文的情况,这个时候就会导致同一个请求中到了子线程时候丢失了链路追踪数据,这个时候就需要我们将链路数据从一个线程拷贝到另外一个线程的上下文中,如果不知道如何拷贝可以考虑下线程间是如何共享数据的比如使用成员变量这种共享变量
如何参与贡献?
如何参与贡献?
可以直接认领任务,后续我们一起沟通,会把任务指派给你
如何参与贡献?
可以直接认领任务,后续我们一起沟通,会把任务指派给你
我希望参与和trace 这块相关的内容。如果可以的话 希望能分配给我 thanks
如何参与贡献?
可以留下钉钉号吗,方便我们联系
如何参与贡献?
可以留下钉钉号吗,方便我们联系
shenfeng970312
dubbo 异步调用采用org.apache.dubbo.rpc.protocol.dubbo.FutureAdapter
包装了CompletableFuture
该类在dubbo-rpc-api
模块下,且相关代码都在该模块下。如果要封装异步trace信息会强制依赖到相关组件,或者加SPI。这样做成本大收益小。所以我认为不应该默认实现,把是否要携带trace的选择交给用户。可以让用户用已下方式实现:
public class ConsumerAsync {
@DubboReference
private DemoService demoService;
@Resource
private ObservationRegistry observationRegistry;
public String doSayHello(String name) throws ExecutionException, InterruptedException {
CompletableFuture<String> stringCompletableFuture = demoService.sayHelloAsync(name);
Observation currentObservation = observationRegistry.getCurrentObservation();
stringCompletableFuture.whenComplete((s, throwable) -> Observation.tryScoped(currentObservation,
()-> System.out.println(s)));
return stringCompletableFuture.get();
}
}
可以的 到时候我们可以把这一部分增加到官方文档提供一种解决方案