导出器

In order to visualize and analyze your telemetry, you will need to export your data to an OpenTelemetry Collector or a backend such as Jaeger, Zipkin, Prometheus or a vendor-specific one.

As part of OpenTelemetry Rust you will find many exporters being available. Among them, the OpenTelemetry Protocol (OTLP) exporters provide the best experience for you as an end-user, since it is a general-purpose telemetry data delivery protocol designed in the scope of the OpenTelemetry project.

To learn more about the OTLP protocol, you can read the OTLP Specification.

Below you will find some introductions on how to set up exporters for OTLP and other common protocols in your code.

OTLP 端点

要将跟踪数据发送到 OTLP 端点(如收集器或 Jaeger),您可以使用导出器 crate,例如 opentelemetry_otlp

[dependencies]
opentelemetry-otlp = { version = "0.13", features = ["default"] }

接下来,配置导出器以指向一个 OTLP 端点。例如,您可以按照以下步骤更新 dice_server.rs 中的 init_tracer 函数,该函数位于 入门指南

fn init_tracer() {
    match SpanExporter::new_tonic(ExportConfig::default(), TonicConfig::default()) {
        Ok(exporter) => {
            global::set_text_map_propagator(TraceContextPropagator::new());
            let provider = TracerProvider::builder()
                .with_simple_exporter(exporter)
                .build();
            global::set_tracer_provider(provider);
        },
        Err(why) => panic!("{:?}", why)
    }

}

要快速尝试 OTLPTraceExporter,您可以在 Docker 容器中运行 Jaeger:

docker run -d --name jaeger \
  -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \
  -e COLLECTOR_OTLP_ENABLED=true \
  -p 6831:6831/udp \
  -p 6832:6832/udp \
  -p 5778:5778 \
  -p 16686:16686 \
  -p 4317:4317 \
  -p 4318:4318 \
  -p 14250:14250 \
  -p 14268:14268 \
  -p 14269:14269 \
  -p 9411:9411 \
  jaegertracing/all-in-one:latest
最后修改 December 10, 2023: translate (a4350d6e)