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

fastrace-opentelemetry

fastrace 的 Opentelemetry 报告器

4 个版本

新版本 0.7.2 2024 年 8 月 16 日
0.7.1 2024 年 8 月 14 日
0.7.0 2024 年 8 月 14 日
0.6.8 2024 年 7 月 16 日

#478调试

Download history 110/week @ 2024-07-12 82/week @ 2024-07-19 666/week @ 2024-07-26 1813/week @ 2024-08-02 1277/week @ 2024-08-09

每月下载量 3,848

Apache-2.0

185KB
4K SLoC

fastrace-opentelemetry

Documentation Crates.io LICENSE

OpenTelemetry 报告器,用于 fastrace.

依赖关系

[dependencies]
fastrace = "0.7"
fastrace-opentelemetry = "0.7"

设置 OpenTelemetry 汇聚器

cd fastrace-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 fastrace::collector::Config;
use fastrace::prelude::*;
use fastrace_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),
);
fastrace::set_reporter(reporter, Config::default());

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

fastrace::flush()

依赖关系

~3–9.5MB
~75K SLoC