应用程序代码和配置
dubbo.application.name=demo-consumer
dubbo.scan.basePackages=com.example.demo
dubbo.registry.address=zookeeper://192.168.99.214:2181
dubbo.application.qos-enable=false
dubbo.protocol.port=20881
dubbo.consumer.filter=tracing
@Configuration
@Import({ DelegatingTracingFilter.class, SpanCustomizingAsyncHandlerInterceptor.class })
public class WebZipkinConfig implements WebMvcConfigurer {
@Resource
private SpanCustomizingAsyncHandlerInterceptor interceptor;
@Resource
private Tracing tracing;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(interceptor);
}
@Bean
public HttpTracing httpTracing() {
return HttpTracing.create(tracing);
}
}
@Configuration
public class ZipkinConfig {
@Bean
public Tracing tracing() {
return Tracing.newBuilder().localServiceName("consumer")
.addSpanHandler(
AsyncZipkinSpanHandler.create(OkHttpSender.create("http://192.168.99.214:9411/api/v2/spans")))
.build();
}
}
@SpringBootApplication
@RestController
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@DubboReference
private DemoService demoService;
@GetMapping("hello")
public String hello() {
demoService.hello("liunancun");
return "hello";
}
}
B应用配置和代码
dubbo.application.name=demo-provider
dubbo.scan.basePackages=com.example.demo
dubbo.registry.address=zookeeper://192.168.99.214:2181
dubbo.protocol.port=20882
dubbo.provider.filter=tracing
dubbo.consumer.filter=tracing
@Configuration
public class ZipkinConfig {
@Bean
public Tracing tracing() {
return Tracing.newBuilder().localServiceName("provider")
.addSpanHandler(
AsyncZipkinSpanHandler.create(OkHttpSender.create("http://192.168.99.214:9411/api/v2/spans")))
.build();
}
}
@DubboService
public class DemoServiceImpl implements DemoService {
@DubboReference
private TestService testService;
@Override
public String hello(String name) {
System.out.println("hello " + name);
testService.test(name);
return "hello " + name;
}
}
C应用配置和代码
dubbo.application.name=demo-test
dubbo.scan.basePackages=com.example.demo
dubbo.registry.address=zookeeper://192.168.99.214:2181
dubbo.protocol.port=20883
dubbo.provider.filter=tracing
@Configuration
public class ZipkinConfig {
@Bean
public Tracing tracing() {
return Tracing.newBuilder().localServiceName("test")
.addSpanHandler(
AsyncZipkinSpanHandler.create(OkHttpSender.create("http://192.168.99.214:9411/api/v2/spans")))
.build();
}
}
@DubboService
public class TestServiceImpl implements TestService {
@Override
public String test(String name) {
System.out.println("test, " + name);
return "test, " + name;
}
}
生成了3个Trace ID
第1个Trace ID只追踪到B应用,没有追踪到C应用