alibaba / spring-cloud-alibaba

Spring Cloud Alibaba provides a one-stop solution for application development for the distributed solutions of Alibaba middleware.
https://sca.aliyun.com
Apache License 2.0
27.91k stars 8.33k forks source link

spring-cloud-alibaba-dubbo替换feign底层的http协议,zipkin链路追踪不生效 #1173

Open Costriod opened 4 years ago

Costriod commented 4 years ago

我们鼓励使用英文,如果不能直接使用,可以使用翻译软件,您仍旧可以保留中文原文。 We recommend using English. If you are non-native English speaker, you can use the translation software.

Which Component eg. Nacos Discovery, Sentinel spring-cloud-alibaba-dubbo 2.1.1.RELEASE spring-cloud-dependencies Hoxton.SR1 spring-boot 2.2.2.RELEASE

Describe the bug A clear and concise description of what the bug is. 如果采用dubbo替换feign client的http协议,ReferenceBean在底层初始化filter chain的时候,TracingFilter的setTracing方法注入了一个null值,根本原因是ExtensionLoader委托SpringExtensionFactory获取bean对象失败(因为SpringExtensionFactory还没来得及给CONTEXTS初始化)

1.必须强制@DubboTransported(filter = {"tracing"})才可以使用tracing(前提条件是使用dubbo协议替换feign的http协议),而配置文件里面的dubbo.consumer.filter或dubbo.provider.filter不起作用

2.ExtensionLoader执行inject操作,注入的tracing对象是委托给SpringExtensionFactory从context里面获取,但是ExtensionLoader inject操作在SpringExtensionFactory context还未初始化之前就执行了,导致SpringExtensionFactory不能从context获取bean,也就导致inject了一个null值

To Reproduce Steps to reproduce the behavior:

  1. 源码在这里 spring-cloud-alibaba-example
  2. 启动zipkin
  3. 启动nacos
  4. 启动server服务
  5. 启动client服务
  6. 访问http://localhost:9001/echo?message=xxx

解决方案:

@FeignClient(name = "spring-cloud-alibaba-server")
public interface EchoService {
    @RequestMapping(value = "/echo")
    @DubboTransported(filter = {"tracing"})
    String echo(@RequestParam("message") String message);
}

@Component
@Order(value = Ordered.HIGHEST_PRECEDENCE)
public class CustomContextAware implements ApplicationContextAware {

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringExtensionFactory.addApplicationContext(applicationContext);
    }
}

Expected behavior A clear and concise description of what you expected to happen. 1.如果不给SpringExtensionFactory初始化一些context,那么tracing是不起作用的,因为brave.dubbo.TracingFilter内部的tracing是一个null值

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here. e.g. MacOS 、Java8 、 Version 0.2.1.RELEASE

xiaokek commented 4 years ago

鼓励使用英文, 是因为想把阿里云打入国外市场?

Costriod commented 4 years ago

鼓励使用英文, 是因为想把阿里云打入国外市场?

我觉得国际化很有必要,在国内自娱自乐也没啥意思,要让老外感受感受爸爸们的温暖,手动狗头doge