use opentelemetry::trace::TracerProvider as _; use opentelemetry_sdk::trace::TracerProvider; use opentelemetry_stdout as stdout; use tracing::{info, span}; use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::Registry; fn main() { // Create a new OpenTelemetry trace pipeline that prints to stdout let provider = TracerProvider::builder() .with_simple_exporter(stdout::SpanExporter::default()) .build(); let tracer = provider.tracer("readme_example"); // Create a tracing layer with the configured tracer let telemetry = tracing_opentelemetry::layer().with_tracer(tracer); // Compose traceon and opentelemetry together let subscriber = Registry::default().with(telemetry).with(traceon::builder()); // Trace executed code tracing::subscriber::with_default(subscriber, || { // Spans will be sent to the configured OpenTelemetry exporter let root = span!(tracing::Level::TRACE, "app_start", work_units = 2); let _enter = root.enter(); info!( "This wll generate an event for the entered span using opentelemetry \ and also log flattened data via traceon." ); }); }