OTlp

这个案例展示了在 Dubbo 项目中以 OpenTelemetry 作为 Tracer,将 Trace 信息上报到 Otlp Collector,再由 collector 转发至 Zipkin、Jagger。

概述

这个案例展示了在 Dubbo 项目中以 OpenTelemetry 作为 Tracer,将 Trace 信息上报到 Otlp Collector,再由 collector 转发至 Zipkin、Jagger。代码地址

有三部分组成:

  • dubbo-samples-spring-boot-tracing-otel-oltp-interface
  • dubbo-samples-spring-boot-tracing-otel-oltp-provider
  • dubbo-samples-spring-boot-tracing-otel-oltp-consumer

案例架构图

案例架构图

快速开始

安装 & 启动 Otlp Collector

按照 OpenTelemetry Collector Quick Start 去启动 otlp collector.

启动 Provider

直接运行org.apache.dubbo.springboot.demo.provider.ProviderApplication directly from IDE.

启动 Consumer

Start org.apache.dubbo.springboot.demo.consumer.ConsumerApplication directly from IDE.

查看 Trace 信息

在浏览器中打开zipkin看板 http://localhost:9411/zipkin/ :

zipkin.png

zipkin.png

在浏览器中打开Jaeger看板 http://localhost:16686/search :

jaeger_search.png

jaeger_detail.png

如何在SpringBoot项目中使用

1. 在你的项目中添加依赖

对于 SpringBoot 项目,你可以使用dubbo-spring-boot-tracing-otel-otlp-starter :

2. <!-- OpenTelemetry as Tracer, Otlp as exporter -->
3. <dependency>
4. <groupId>org.apache.dubbo</groupId>
5. <artifactId>dubbo-spring-boot-tracing-otel-otlp-starter</artifactId>
6. </dependency>

2. 配置

application.yml

1. dubbo:
2. tracing:
3. enabled: true # default is false
4. sampling:
5. probability: 0.5 # sampling rate, default is 0.1
6. propagation:
7. type: W3C # W3C/B3 default is W3C
8. tracing-exporter:
9. otlp-config:
10. endpoint: http://localhost:4317
11. timeout: 10s # default is 10s
12. compression-method: none # none/gzip The method used to compress payloads, default is "none"
13. headers: # customized added headers, default is empty
14. auth: admin

16. # tracing info output to logging
17. logging:
18. level:
19. root: info
20. pattern:
21. console: '[%d{dd/MM/yy HH:mm:ss:SSS z}] %t %5p %c{2} [%X{traceId:-}, %X{spanId:-}]: %m%n'

如何基于Dubbo API使用

1. 在你的项目中添加依赖

1. <!-- 必选,dubbo-tracing核心依赖 -->
2. <dependency>
3. <groupId>org.apache.dubbo</groupId>
4. <artifactId>dubbo-tracing</artifactId>
5. </dependency>
6. <!-- Opentelemetry as Tracer -->
7. <dependency>
8. <groupId>io.micrometer</groupId>
9. <artifactId>micrometer-tracing-bridge-otel</artifactId>
10. </dependency>
11. <!-- OTlp as exporter -->
12. <dependency>
13. <groupId>io.opentelemetry</groupId>
14. <artifactId>opentelemetry-exporter-otlp</artifactId>
15. </dependency>

2. 配置

1. TracingConfig tracingConfig = new TracingConfig();
2. // 开启dubbo tracing
3. tracingConfig.setEnabled(true);
4. // 设置采样率
5. tracingConfig.setSampling(new SamplingConfig(1.0f));
6. // 设置Propagation,默认为W3C,可选W3C/B3
7. tracingConfig.setPropagation(new PropagationConfig("W3C"));
8. // 设置trace上报
9. ExporterConfig exporterConfig = new ExporterConfig();
10. // 设置将trace上报到Zipkin
11. exporterConfig.setZipkin(new ExporterConfig.OtlpConfig("http://localhost:4317", Duration.ofSeconds(10), "none"));
12. tracingConfig.setExporter(exporterConfig);

最后修改 September 13, 2024: Refactor website structure (#2860) (1a4b998f54b)