Tracing OpenTelemetry
An OpenTelemetry layer for the tracing library.
Tracers
Currently supports the Jaeger exporter via opentelemetry-jaeger and Zipkin via opentelemetry-zipkin.
Examples
Basic Usage
#[macro_use]
extern crate tracing;
use opentelemetry::{api::Provider, sdk};
use tracing_opentelemetry::OpenTelemetryLayer;
use tracing_subscriber::{Layer, Registry};
use tracing_subscriber::layer::SubscriberExt;
fn main() {
// Create a new tracer
let tracer = sdk::Provider::default().get_tracer("component_name");
// Create a new OpenTelemetry tracing layer
let telemetry = OpenTelemetryLayer::with_tracer(tracer);
let subscriber = Registry::default().with(telemetry);
// Trace executed code
tracing::subscriber::with_default(subscriber, || {
let root = span!(tracing::Level::TRACE, "app_start", work_units = 2);
let _enter = root.enter();
error!("This event will be logged in the root span.");
});
}
report.rs
example
Execute # Run jaeger in background
$ docker run -d -p6831:6831/udp -p6832:6832/udp -p16686:16686 jaegertracing/all-in-one:latest
# Report example spans
$ cargo run --example report
# View spans (see the image below)
$ firefox http://localhost:16686/