Crates.io | minitrace-opentelemetry |
lib.rs | minitrace-opentelemetry |
version | 0.6.7 |
source | src |
created_at | 2023-07-28 07:56:57.40394 |
updated_at | 2024-06-23 09:29:03.237389 |
description | Opentelemetry reporter for minitrace-rust |
homepage | https://github.com/tikv/minitrace-rust |
repository | https://github.com/tikv/minitrace-rust |
max_upload_size | |
id | 928262 |
size | 22,407 |
OpenTelemetry reporter for minitrace
.
[dependencies]
minitrace = "0.6"
minitrace-opentelemetry = "0.6"
cd minitrace-opentelemetry/examples
docker compose up -d
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/
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()