#tracing #open-telemetry #jaeger #datadog #spans

minitrace-opentelemetry

minitrace-rust的Opentelemetry报告器

10个版本

0.6.7 2024年6月23日
0.6.6 2024年5月31日
0.6.4 2024年2月8日
0.6.3 2024年1月26日
0.5.0 2023年7月28日

#9 in #span

Download history 2811/week @ 2024-05-01 2816/week @ 2024-05-08 2997/week @ 2024-05-15 2783/week @ 2024-05-22 2705/week @ 2024-05-29 2387/week @ 2024-06-05 2260/week @ 2024-06-12 2789/week @ 2024-06-19 3427/week @ 2024-06-26 3710/week @ 2024-07-03 3967/week @ 2024-07-10 2581/week @ 2024-07-17 2508/week @ 2024-07-24 892/week @ 2024-07-31 1408/week @ 2024-08-07 2791/week @ 2024-08-14

8,182 每月下载量

Apache-2.0

180KB
3.5K SLoC

minitrace-opentelemetry

Documentation Crates.io LICENSE

OpenTelemetryminitrace 提供报告器。

依赖项

[dependencies]
minitrace = "0.6"
minitrace-opentelemetry = "0.6"

设置OpenTelemetry收集器

cd minitrace-opentelemetry/examples
docker compose up -d

cargo run --example synchronous

Jaeger UI 可在 http://127.0.0.1:16686/ 上访问

Zipkin UI 可在 http://127.0.0.1:9411/ 上访问

向OpenTelemetry收集器报告

use std::borrow::Cow;
use std::time::Duration;
use minitrace::collector::Config;
use minitrace::prelude::*;
use minitrace_opentelemetry::OpenTelemetryReporter;
use opentelemetry_otlp::{SpanExporter, ExportConfig, Protocol, TonicConfig};
use opentelemetry::trace::SpanKind;
use opentelemetry_sdk::Resource;
use opentelemetry::KeyValue;
use opentelemetry::InstrumentationLibrary;
use opentelemetry_otlp::WithExportConfig;

// Initialize reporter
let reporter = OpenTelemetryReporter::new(
    opentelemetry_otlp::new_exporter()
        .tonic()
        .with_endpoint("http://127.0.0.1:4317".to_string())
        .with_protocol(opentelemetry_otlp::Protocol::Grpc)
        .with_timeout(Duration::from_secs(
            opentelemetry_otlp::OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT,
        ))
        .build_span_exporter()
        .expect("initialize oltp exporter"),
    SpanKind::Server,
    Cow::Owned(Resource::new([KeyValue::new("service.name", "asynchronous")])),
    InstrumentationLibrary::new("example-crate", Some(env!("CARGO_PKG_VERSION")), None::<&'static str>, None),
);
minitrace::set_reporter(reporter, Config::default());

{
    // Start tracing
    let root = Span::root("root", SpanContext::random());
}

minitrace::flush()

依赖项

~3–9MB
~79K SLoC