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

fastrace-opentelemetry

Opentelemetry reporter for fastrace

7 releases

new 0.8.0 Nov 18, 2024
0.7.4 Oct 27, 2024
0.7.3 Sep 23, 2024
0.7.2 Aug 16, 2024
0.6.8 Jul 16, 2024

#655 in Debugging

Download history 1740/week @ 2024-08-01 1403/week @ 2024-08-08 1697/week @ 2024-08-15 998/week @ 2024-08-22 1363/week @ 2024-08-29 1421/week @ 2024-09-05 1009/week @ 2024-09-12 2058/week @ 2024-09-19 1368/week @ 2024-09-26 925/week @ 2024-10-03 2177/week @ 2024-10-10 2032/week @ 2024-10-17 2268/week @ 2024-10-24 1936/week @ 2024-10-31 1782/week @ 2024-11-07 1580/week @ 2024-11-14

8,028 downloads per month

Apache-2.0

185KB
4K SLoC

fastrace-opentelemetry

Documentation Crates.io LICENSE

OpenTelemetry reporter for fastrace.

Dependencies

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

Setup OpenTelemetry Collector

Start OpenTelemetry Collector with Jaeger and Zipkin receivers:

docker compose -f examples/docker-compose.yaml up

Then, run the synchronous example:

cargo run --example synchronous

Jaeger UI is available on http://127.0.0.1:16686/

Zipkin UI is available on http://127.0.0.1:9411/

Report to OpenTelemetry Collector

use std::borrow::Cow;
use std::time::Duration;
use fastrace::collector::Config;
use fastrace::prelude::*;
use fastrace_opentelemetry::OpenTelemetryReporter;
use opentelemetry_otlp::ExportConfig;
use opentelemetry_otlp::Protocol;
use opentelemetry_otlp::SpanExporter;
use opentelemetry_otlp::TonicConfig;
use opentelemetry::trace::SpanKind;
use opentelemetry_sdk::Resource;
use opentelemetry::KeyValue;
use opentelemetry::InstrumentationScope;
use opentelemetry_otlp::WithExportConfig;

// Initialize reporter
let reporter = OpenTelemetryReporter::new(
    SpanExporter::builder()
        .with_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()
        .expect("initialize oltp exporter"),
    SpanKind::Server,
    Cow::Owned(Resource::new([KeyValue::new("service.name", "asynchronous")])),
    InstrumentationScope::builder("example-crate").with_version(env!("CARGO_PKG_VERSION")).build(),
);
fastrace::set_reporter(reporter, Config::default());

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

fastrace::flush()

Dependencies

~3–8.5MB
~75K SLoC