You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by yi...@apache.org on 2022/07/29 08:49:45 UTC

[doris] branch master updated: [tracing] Support opentelemtry collector. (#10864)

This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new d3c88471ad [tracing] Support opentelemtry collector. (#10864)
d3c88471ad is described below

commit d3c88471ad566eef5b7aef62b7d51cc24ba84fbb
Author: luozenglin <37...@users.noreply.github.com>
AuthorDate: Fri Jul 29 16:49:40 2022 +0800

    [tracing] Support opentelemtry collector. (#10864)
    
    * [tracing] Support opentelemtry collector.
    
    1. support for exporting traces to multiple distributed tracing system via collector;
    2. support using collector to process traces.
---
 be/CMakeLists.txt                                  |  16 +++
 be/src/common/config.h                             |  16 +++
 be/src/service/doris_main.cpp                      |   2 +-
 be/src/util/telemetry/telemetry.cpp                |  23 +++-
 be/src/util/telemetry/telemetry.h                  |   2 +-
 docs/en/docs/admin-manual/tracing.md               | 139 ++++++++++++++++++-
 docs/zh-CN/docs/admin-manual/tracing.md            | 152 +++++++++++++++++++--
 fe/fe-core/pom.xml                                 |   3 +-
 .../main/java/org/apache/doris/common/Config.java  |  18 +++
 .../apache/doris/common/telemetry/Telemetry.java   |  24 ++--
 10 files changed, 358 insertions(+), 37 deletions(-)

diff --git a/be/CMakeLists.txt b/be/CMakeLists.txt
index 7f11c4cb9c..f47dfd978f 100644
--- a/be/CMakeLists.txt
+++ b/be/CMakeLists.txt
@@ -352,6 +352,18 @@ set_target_properties(opentelemetry_trace PROPERTIES IMPORTED_LOCATION ${THIRDPA
 add_library(opentelemetry_http_client_curl STATIC IMPORTED)
 set_target_properties(opentelemetry_http_client_curl PROPERTIES IMPORTED_LOCATION ${THIRDPARTY_DIR}/lib64/libopentelemetry_http_client_curl.a)
 
+add_library(opentelemetry_exporter_otlp_http STATIC IMPORTED)
+set_target_properties(opentelemetry_exporter_otlp_http PROPERTIES IMPORTED_LOCATION ${THIRDPARTY_DIR}/lib64/libopentelemetry_exporter_otlp_http.a)
+
+add_library(opentelemetry_exporter_otlp_http_client STATIC IMPORTED)
+set_target_properties(opentelemetry_exporter_otlp_http_client PROPERTIES IMPORTED_LOCATION ${THIRDPARTY_DIR}/lib64/libopentelemetry_exporter_otlp_http_client.a)
+
+add_library(opentelemetry_otlp_recordable STATIC IMPORTED)
+set_target_properties(opentelemetry_otlp_recordable PROPERTIES IMPORTED_LOCATION ${THIRDPARTY_DIR}/lib64/libopentelemetry_otlp_recordable.a)
+
+add_library(opentelemetry_proto STATIC IMPORTED)
+set_target_properties(opentelemetry_proto PROPERTIES IMPORTED_LOCATION ${THIRDPARTY_DIR}/lib64/libopentelemetry_proto.a)
+
 add_library(xml2 STATIC IMPORTED)
 set_target_properties(xml2 PROPERTIES IMPORTED_LOCATION ${THIRDPARTY_DIR}/lib64/libxml2.a)
 
@@ -678,6 +690,10 @@ set(COMMON_THIRDPARTY
     opentelemetry_exporter_ostream_span
     opentelemetry_trace
     opentelemetry_http_client_curl
+    opentelemetry_exporter_otlp_http
+    opentelemetry_exporter_otlp_http_client
+    opentelemetry_otlp_recordable
+    opentelemetry_proto
     ${AWS_LIBS}
     # put this after lz4 to avoid using lz4 lib in librdkafka
     librdkafka_cpp
diff --git a/be/src/common/config.h b/be/src/common/config.h
index 06c8bebf2c..36cfeb684d 100644
--- a/be/src/common/config.h
+++ b/be/src/common/config.h
@@ -732,9 +732,25 @@ CONF_String(function_service_protocol, "h2:grpc");
 // use which load balancer to select server to connect
 CONF_String(rpc_load_balancer, "rr");
 
+// Enable tracing
+// If this configuration is enabled, you should also specify the trace_export_url.
 CONF_Bool(enable_tracing, "false");
 
+// Enable opentelemtry collector
+CONF_Bool(enable_otel_collector, "false");
+
+// Current support for exporting traces:
+// zipkin: Export traces directly to zipkin, which is used to enable the tracing feature quickly.
+// collector: The collector can be used to receive and process traces and support export to a variety of
+//   third-party systems.
+CONF_mString(trace_exporter, "zipkin");
+CONF_Validator(trace_exporter, [](const std::string& config) -> bool {
+    return config == "zipkin" || config == "collector";
+});
+
 // The endpoint to export spans to.
+// export to zipkin like: http://127.0.0.1:9411/api/v2/spans
+// export to collector like: http://127.0.0.1:4318/v1/traces
 CONF_String(trace_export_url, "http://127.0.0.1:9411/api/v2/spans");
 
 // The maximum buffer/queue size to collect span. After the size is reached, spans are dropped.
diff --git a/be/src/service/doris_main.cpp b/be/src/service/doris_main.cpp
index a78bb801b1..d62230a165 100644
--- a/be/src/service/doris_main.cpp
+++ b/be/src/service/doris_main.cpp
@@ -397,7 +397,7 @@ int main(int argc, char** argv) {
     // SHOULD be called after exec env is initialized.
     EXIT_IF_ERROR(engine->start_bg_threads());
 
-    doris::telemetry::initTracer();
+    doris::telemetry::init_tracer();
 
     // begin to start services
     doris::ThriftRpcHelper::setup(exec_env);
diff --git a/be/src/util/telemetry/telemetry.cpp b/be/src/util/telemetry/telemetry.cpp
index bd3d90e48a..5bbd7d4537 100644
--- a/be/src/util/telemetry/telemetry.cpp
+++ b/be/src/util/telemetry/telemetry.cpp
@@ -20,6 +20,7 @@
 #include "common/config.h"
 #include "opentelemetry/context/propagation/global_propagator.h"
 #include "opentelemetry/context/propagation/text_map_propagator.h"
+#include "opentelemetry/exporters/otlp/otlp_http_exporter.h"
 #include "opentelemetry/exporters/zipkin/zipkin_exporter.h"
 #include "opentelemetry/nostd/shared_ptr.h"
 #include "opentelemetry/sdk/trace/batch_span_processor.h"
@@ -34,16 +35,28 @@ namespace trace_sdk = opentelemetry::sdk::trace;
 namespace zipkin = opentelemetry::exporter::zipkin;
 namespace resource = opentelemetry::sdk::resource;
 namespace propagation = opentelemetry::context::propagation;
+namespace otlp = opentelemetry::exporter::otlp;
 
-void doris::telemetry::initTracer() {
+void doris::telemetry::init_tracer() {
     if (!doris::config::enable_tracing) {
         return;
     }
 
-    // ZipkinExporter converts span to zipkin's format and exports span to zipkin.
-    zipkin::ZipkinExporterOptions opts;
-    opts.endpoint = doris::config::trace_export_url;
-    auto exporter = std::unique_ptr<trace_sdk::SpanExporter>(new zipkin::ZipkinExporter(opts));
+    std::unique_ptr<trace_sdk::SpanExporter> exporter = nullptr;
+    std::string trace_exporter = config::trace_exporter;
+    boost::to_lower(trace_exporter);
+    if (trace_exporter.compare("collector") == 0) {
+        otlp::OtlpHttpExporterOptions opts {};
+        opts.url = doris::config::trace_export_url;
+        exporter = std::make_unique<otlp::OtlpHttpExporter>(opts);
+    } else if (trace_exporter.compare("zipkin") == 0) {
+        // ZipkinExporter converts span to zipkin's format and exports span to zipkin.
+        zipkin::ZipkinExporterOptions opts {};
+        opts.endpoint = doris::config::trace_export_url;
+        exporter = std::make_unique<zipkin::ZipkinExporter>(opts);
+    } else {
+        LOG(FATAL) << "unknown value " << trace_exporter << " of trace_exporter in be.conf";
+    }
 
     // BatchSpanProcessor exports span by batch.
     trace_sdk::BatchSpanProcessorOptions batchOptions;
diff --git a/be/src/util/telemetry/telemetry.h b/be/src/util/telemetry/telemetry.h
index 622cd22272..96f8667901 100644
--- a/be/src/util/telemetry/telemetry.h
+++ b/be/src/util/telemetry/telemetry.h
@@ -67,7 +67,7 @@ using OpentelemetryScope = opentelemetry::trace::Scope;
 
 namespace telemetry {
 
-void initTracer();
+void init_tracer();
 
 /// Return NoopTracer, the span generated by NoopTracer is NoopSpan, and the method bodies of
 /// NoopTracer and NoopSpan are empty.
diff --git a/docs/en/docs/admin-manual/tracing.md b/docs/en/docs/admin-manual/tracing.md
index b4cdf048a6..17802252b8 100644
--- a/docs/en/docs/admin-manual/tracing.md
+++ b/docs/en/docs/admin-manual/tracing.md
@@ -28,20 +28,24 @@ under the License.
 
 Tracing records the life cycle of a request execution in the system, including the request and its sub-procedure call links, execution time and statistics, which can be used for slow query location, performance bottleneck analysis, etc.
 
-# Operation process
+## Principle
 
-## Deploy distributed tracing system
+doris is responsible for collecting traces and exporting them to a third-party tracing analysis system, which is responsible for the presentation and storage of traces.
 
-Currently supports [Zipkin](https://zipkin.io/) ,More ldistributed tracing systems will be supported in the future.
+## Quick Start
+
+doris currently supports exporting traces directly to [zipkin](https://zipkin.io/).
+
+### Deploy zipkin
 
 ```
 curl -sSL https://zipkin.io/quickstart.sh | bash -s
 java -jar zipkin.jar
 ```
 
-## Configuring and starting Doris
+### Configuring and starting Doris
 
-### Add configuration to fe.conf
+#### Add configuration to fe.conf
 
 ```
 enable_tracing = true
@@ -50,7 +54,7 @@ enable_tracing = true
 trace_export_url = http://127.0.0.1:9411/api/v2/spans
 ```
 
-### Add configuration to be.conf
+#### Add configuration to be.conf
 ```
 enable_tracing = true
 
@@ -67,14 +71,135 @@ max_span_export_batch_size=512
 export_span_schedule_delay_millis=500
 ```
 
-### Start fe and be
+#### Start fe and be
 ```
 sh fe/bin/start_fe.sh --daemon
 sh be/bin/start_be.sh --daemon
 ```
 
 ### Executing a query
+```
+...
+```
 
 ### View zipkin UI
 
 The browser opens `http://127.0.0.1:9411/zipkin/` to view the query tracing.
+
+## Using opentelemetry collector
+
+Use the opentelemetry collector to export traces to other systems such as zipkin, jaeger, skywalking, or to database systems and files.  For more details, refer to [collector exporter](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter).
+
+Meanwhile, opentelemetry collector provides a rich set of operators to process traces. For example, [filterprocessor](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/filterprocessor) , [tailsamplingprocessor](hhttps://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/tailsamplingprocessor). For more details, refer to [collector processor](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor).
+
+traces export path: doris->collector->zipkin etc.
+
+### Deploy opentelemetry collector
+
+opentelemetry has released collector [core](https://github.com/open-telemetry/opentelemetry-collector) and [contrib](https://github.com/open-telemetry/opentelemetry-collector-contrib), contrib provides richer features, here is an example of contrib version.
+
+#### Download collector
+
+Download otelcol-contrib, available on the official website [more precompiled versions for more platforms](https://github.com/open-telemetry/opentelemetry-collector-releases/releases)
+
+```
+wget https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.55.0/otelcol-contrib_0.55.0_linux_amd64.tar.gz
+
+tar -zxvf otelcol-contrib_0.55.0_linux_amd64.tar.gz
+```
+
+#### Generate configuration file
+
+The collector configuration file is divided into 5 parts: `receivers`, `processors`, `exporters`, `extensions`, and `service`. Among them, receivers, processors and exporters define the way to receive, process and export data respectively; extensions are optional and are used to extend tasks that do not involve processing telemetry data; service specifies which components are used in the collector. See [collector configuration](https://opentelemetry.io/docs/collector/deployment/).
+
+The following configuration file uses the otlp (OpenTelemetry Protocol) protocol to receive traces data, perform batch processing and filter out traces longer than 50ms, and finally export them to zipkin and file.
+
+```
+cat > otel-collector-config.yaml << EOF
+receivers:
+  otlp:
+    protocols:
+      http:
+
+exporters:
+  zipkin:
+    endpoint: "http://10.81.85.90:8791/api/v2/spans"
+  file:
+    path: ./filename.json
+
+processors:
+  batch:
+  tail_sampling:
+    policies:
+      {
+        name: duration_policy,
+        type: latency,
+        latency: {threshold_ms: 50}
+      }
+
+extensions:
+
+service:
+  pipelines:
+    traces:
+      receivers: [otlp]
+      processors: [batch, tail_sampling]
+      exporters: [zipkin, file]
+EOF
+```
+
+#### Start collector
+
+```
+nohup ./otelcol-contrib --config=otel-collector-config.yaml &
+```
+
+### Configuring and starting Doris
+
+#### Add configuration to fe.conf
+
+```
+enable_tracing = true
+
+# enable opentelemetry collector
+trace_exporter = collector
+
+# Configure traces export to collector, 4318 is the default port for collector otlp http
+trace_export_url = http://127.0.0.1:4318/v1/traces
+```
+
+#### Add configuration to be.conf
+```
+enable_tracing = true
+
+# enable opentelemetry collector
+trace_exporter = collector
+
+# Configure traces export to collector, 4318 is the default port for collector otlp http
+trace_export_url = http://127.0.0.1:4318/v1/traces
+
+# Queue size for caching spans. span export will be triggered once when the number of spans reaches half of the queue capacity. spans arriving in the queue will be discarded when the queue is full.
+max_span_queue_size=2048
+
+# The maximum number of spans to export in a single pass.
+max_span_export_batch_size=512
+
+# Maximum interval for exporting span
+export_span_schedule_delay_millis=500
+```
+
+#### Start fe and be
+```
+sh fe/bin/start_fe.sh --daemon
+sh be/bin/start_be.sh --daemon
+```
+
+### Executing a query
+```
+...
+```
+
+### View zipkin UI
+```
+...
+```
\ No newline at end of file
diff --git a/docs/zh-CN/docs/admin-manual/tracing.md b/docs/zh-CN/docs/admin-manual/tracing.md
index 35940589c4..aab76ff462 100644
--- a/docs/zh-CN/docs/admin-manual/tracing.md
+++ b/docs/zh-CN/docs/admin-manual/tracing.md
@@ -28,20 +28,23 @@ under the License.
 
 链路追踪(tracing)记录了一次请求在系统中的执行的生命周期,包括请求及其子过程调用链路、执行时间及统计信息,可用于慢查询定位、性能瓶颈分析等。
 
-# 操作流程
+## 原理
 
-## 部署链路分析系统
+doris负责收集traces,并导出到第三方链路分析系统,由链路分析系统负责traces的展示和存储。
 
-目前支持 [Zipkin](https://zipkin.io/) ,未来会支持更多链路分析系统。
+## 快速搭建
+doris目前支持直接将traces导出到 [zipkin](https://zipkin.io/) 中。
+
+### 部署 zipkin
 
 ```
 curl -sSL https://zipkin.io/quickstart.sh | bash -s
 java -jar zipkin.jar
 ```
 
-## 配置及启动Doris
+### 配置及启动Doris
 
-### 添加配置到fe.conf
+#### 添加配置到fe.conf
 
 ```
 # 开启链路追踪
@@ -51,32 +54,153 @@ enable_tracing = true
 trace_export_url = http://127.0.0.1:9411/api/v2/spans
 ```
 
-### 添加配置到be.conf
+#### 添加配置到be.conf
 ```
-# 开启链路追踪
+# 开启链路追踪。
 enable_tracing = true
 
-# 配置traces导出到zipkin
+# 配置traces导出到zipkin。
 trace_export_url = http://127.0.0.1:9411/api/v2/spans
 
-# 缓存span的队列大小。span数量达到队列容量一半时将触发一次span导出,队列满后到达队列的span将被丢弃。
+# 可选。缓存span的队列大小。span数量达到队列容量一半时将触发一次span导出,队列满后到达队列的span将被丢弃。
 max_span_queue_size=2048
 
-# 单次导出span的最大数量。
+# 可选。单次导出span的最大数量。
 max_span_export_batch_size=512
 
-# 导出span的最大间隔时间
+# 可选。导出span的最大间隔时间。
 export_span_schedule_delay_millis=500
 ```
 
-### 启动fe和be
+#### 启动fe和be
 ```
 sh fe/bin/start_fe.sh --daemon
 sh be/bin/start_be.sh --daemon
 ```
 
-## 执行查询
+### 执行查询
+```
+...
+```
 
-## 查看zipkin UI
+### 查看zipkin UI
 
 浏览器打开`http://127.0.0.1:9411/zipkin/` 可查看查询链路。
+
+## 使用opentelemetry collector
+
+使用opentelemetry collector 可将traces导出到其他系统例如zipkin、jaeger、skywalking,或者数据库系统和文件中。 详情参考 [collector exporter](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter) 。
+
+同时 opentelemetry collector 提供了丰富的算子用来处理traces。例如[过滤 spans](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/filterprocessor) 、[尾采样](hhttps://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/tailsamplingprocessor)。详情参考[collector processor](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor)。
+
+traces导出的路径:doris -> collector -> zipkin等。
+
+### 部署 opentelemetry collector
+
+opentelemetry 发布了collector [core](https://github.com/open-telemetry/opentelemetry-collector) 和 [contrib](https://github.com/open-telemetry/opentelemetry-collector-contrib), contrib提供了更丰富的功能,这里以contrib版举例。
+
+#### 下载 collector
+
+下载 otelcol-contrib, 可在官网下载[更多平台预编译版](https://github.com/open-telemetry/opentelemetry-collector-releases/releases)
+
+```
+wget https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.55.0/otelcol-contrib_0.55.0_linux_amd64.tar.gz
+
+tar -zxvf otelcol-contrib_0.55.0_linux_amd64.tar.gz
+```
+
+#### 生成配置文件
+
+collector 配置文件分为5部分:`receivers`、`processors`、`exporters`、`extensions`、`service`。其中receivers、processors、exporters分别定义了接收、处理、导出数据的方式;extensions是可选的,用于扩展主要用于不涉及处理遥测数据的任务;service指定在collector中使用哪些组件。可参考 [collector configuration](https://opentelemetry.io/docs/collector/deployment/)。
+
+下面配置文件使用otlp(OpenTelemetry Protocol)协议接收traces数据,进行批处理并过滤掉时间超过50ms的traces, 最终导出到zipkin和文件中。
+```
+cat > otel-collector-config.yaml << EOF
+receivers:
+  otlp:
+    protocols:
+      http:
+
+exporters:
+  zipkin:
+    endpoint: "http://10.81.85.90:8791/api/v2/spans"
+  file:
+    path: ./filename.json
+
+processors:
+  batch:
+  tail_sampling:
+    policies:
+      {
+        name: duration_policy,
+        type: latency,
+        latency: {threshold_ms: 50}
+      }
+
+extensions:
+
+service:
+  pipelines:
+    traces:
+      receivers: [otlp]
+      processors: [batch, tail_sampling]
+      exporters: [zipkin, file]
+EOF
+```
+
+#### 启动 collector
+
+```
+nohup ./otelcol-contrib --config=otel-collector-config.yaml &
+```
+
+### 配置及启动Doris
+
+#### 添加配置到fe.conf
+
+```
+# 开启链路追踪
+enable_tracing = true
+
+# 启用opentelemetry collector。
+trace_exporter = collector
+
+# 配置traces导出到collector,4318为collector otlp http默认端口。
+trace_export_url = http://127.0.0.1:4318/v1/traces
+```
+
+#### 添加配置到be.conf
+```
+# 开启链路追踪。
+enable_tracing = true
+
+# 启用opentelemetry collector。
+trace_exporter = collector
+
+# 配置traces导出到collector,4318为collector otlp http默认端口。
+trace_export_url = http://127.0.0.1:4318/v1/traces
+
+# 可选。缓存span的队列大小。span数量达到队列容量一半时将触发一次span导出,队列满后到达队列的span将被丢弃。
+max_span_queue_size=2048
+
+# 可选。单次导出span的最大数量。
+max_span_export_batch_size=512
+
+# 可选。导出span的最大间隔时间。
+export_span_schedule_delay_millis=500
+```
+
+#### 启动fe和be
+```
+sh fe/bin/start_fe.sh --daemon
+sh be/bin/start_be.sh --daemon
+```
+
+### 执行查询
+```
+...
+```
+### 查看traces
+```
+...
+```
diff --git a/fe/fe-core/pom.xml b/fe/fe-core/pom.xml
index 8e7d4552b6..b036cf9033 100644
--- a/fe/fe-core/pom.xml
+++ b/fe/fe-core/pom.xml
@@ -608,9 +608,10 @@ under the License.
             <version>1.14.0</version>
         </dependency>
 
+        <!-- https://mvnrepository.com/artifact/io.opentelemetry/opentelemetry-exporter-otlp-http-trace -->
         <dependency>
             <groupId>io.opentelemetry</groupId>
-            <artifactId>opentelemetry-exporter-otlp-trace</artifactId>
+            <artifactId>opentelemetry-exporter-otlp-http-trace</artifactId>
             <version>1.14.0</version>
         </dependency>
 
diff --git a/fe/fe-core/src/main/java/org/apache/doris/common/Config.java b/fe/fe-core/src/main/java/org/apache/doris/common/Config.java
index db79c6cbdb..0a6cceb157 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/common/Config.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/common/Config.java
@@ -1631,9 +1631,27 @@ public class Config extends ConfigBase {
     @ConfField(mutable = true, masterOnly = true)
     public static int cbo_default_sample_percentage = 10;
 
+    /**
+     * If this configuration is enabled, you should also specify the trace_export_url.
+     */
     @ConfField(mutable = false, masterOnly = false)
     public static boolean enable_tracing = false;
 
+    /**
+     * Current support for exporting traces:
+     *   zipkin: Export traces directly to zipkin, which is used to enable the tracing feature quickly.
+     *   collector: The collector can be used to receive and process traces and support export to a variety of
+     *     third-party systems.
+     * If this configuration is enabled, you should also specify the enable_tracing=true and trace_export_url.
+     */
+    @ConfField(mutable = false, masterOnly = false)
+    public static String trace_exporter = "zipkin";
+
+    /**
+     * The endpoint to export spans to.
+     * export to zipkin like: http://127.0.0.1:9411/api/v2/spans
+     * export to collector like: http://127.0.0.1:4318/v1/traces
+     */
     @ConfField(mutable = false, masterOnly = false)
     public static String trace_export_url = "http://127.0.0.1:9411/api/v2/spans";
 
diff --git a/fe/fe-core/src/main/java/org/apache/doris/common/telemetry/Telemetry.java b/fe/fe-core/src/main/java/org/apache/doris/common/telemetry/Telemetry.java
index 3e434e7a0b..887405f325 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/common/telemetry/Telemetry.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/common/telemetry/Telemetry.java
@@ -27,7 +27,7 @@ import io.opentelemetry.api.trace.Span;
 import io.opentelemetry.api.trace.Tracer;
 import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator;
 import io.opentelemetry.context.propagation.ContextPropagators;
-import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter;
+import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter;
 import io.opentelemetry.exporter.zipkin.ZipkinSpanExporter;
 import io.opentelemetry.sdk.OpenTelemetrySdk;
 import io.opentelemetry.sdk.resources.Resource;
@@ -47,20 +47,28 @@ public class Telemetry {
 
     private static OpenTelemetry openTelemetry = OpenTelemetry.noop();
 
+    public enum DorisTraceExporter {
+        zipkin, collector
+    }
+
     /**
      * Initialize {@link OpenTelemetry} with {@link SdkTracerProvider}, {@link BatchSpanProcessor},
      * {@link ZipkinSpanExporter} and {@link W3CTraceContextPropagator}.
      */
-    public static void initOpenTelemetry() {
+    public static void initOpenTelemetry() throws Exception {
         if (!Config.enable_tracing) {
             return;
         }
 
-        // todo: It may be possible to use oltp exporter to export telemetry data to otel collector,
-        //  which in turn processes and sends telemetry data to multiple back-ends (e.g. zipkin, Prometheus,
-        //  Fluent Bit, etc.) to improve scalability.
-        String httpUrl = Config.trace_export_url;
-        SpanExporter spanExporter = zipkinExporter(httpUrl);
+        String traceExportUrl = Config.trace_export_url;
+        SpanExporter spanExporter;
+        if (DorisTraceExporter.collector.name().equalsIgnoreCase(Config.trace_exporter)) {
+            spanExporter = oltpExporter(traceExportUrl);
+        } else if (DorisTraceExporter.zipkin.name().equalsIgnoreCase(Config.trace_exporter)) {
+            spanExporter = zipkinExporter(traceExportUrl);
+        } else {
+            throw new Exception("unknown value " + Config.trace_exporter + " of trace_exporter in fe.conf");
+        }
 
         String serviceName = "FRONTEND:" + Env.getCurrentEnv().getSelfNode().first;
         Resource serviceNameResource = Resource.create(
@@ -84,7 +92,7 @@ public class Telemetry {
     }
 
     private static SpanExporter oltpExporter(String httpUrl) {
-        return OtlpGrpcSpanExporter.builder().setEndpoint(httpUrl).build();
+        return OtlpHttpSpanExporter.builder().setEndpoint(httpUrl).build();
     }
 
     public static OpenTelemetry getOpenTelemetry() {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org