diff --git a/Cargo.toml b/Cargo.toml index bc11dfc..627ec01 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,10 @@ path = "src/main.rs" [dependencies] nom = "7.1.1" +opentelemetry = "0.17.0" +opentelemetry-jaeger = "0.16.0" tracing = "0.1.37" +tracing-opentelemetry = "0.17.2" tracing-subscriber = {version="0.3.16", features=["env-filter"]} [features] diff --git a/src/main.rs b/src/main.rs index 2d4a3dc..cc49471 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,10 @@ #![feature(round_char_boundary)] use crate::parser::document; -use tracing_subscriber::fmt::format::FmtSpan; use tracing_subscriber::EnvFilter; mod parser; +use tracing_subscriber::fmt; +use tracing_subscriber::layer::SubscriberExt; +use tracing_subscriber::util::SubscriberInitExt; const TEST_DOC: &'static str = include_str!("../toy_language.txt"); @@ -16,17 +18,25 @@ fn main() -> Result<(), Box> { fn init_telemetry() -> Result<(), Box> { let env_filter = EnvFilter::try_from_default_env().unwrap_or(EnvFilter::new("WARN")); - let format = tracing_subscriber::fmt::format() + + let stdout = fmt::Layer::new() .pretty() .with_file(true) .with_line_number(true) .with_thread_ids(false) .with_target(false); - let subscriber = tracing_subscriber::fmt() - .event_format(format) - .with_span_events(FmtSpan::ENTER | FmtSpan::EXIT) - .with_env_filter(env_filter) - .finish(); - tracing::subscriber::set_global_default(subscriber)?; + + opentelemetry::global::set_text_map_propagator(opentelemetry_jaeger::Propagator::new()); + let tracer = opentelemetry_jaeger::new_pipeline() + .with_service_name("toy_language") + .install_simple()?; + + let opentelemetry = tracing_opentelemetry::layer().with_tracer(tracer); + + tracing_subscriber::registry() + .with(env_filter) + .with(opentelemetry) + .with(stdout) + .try_init()?; Ok(()) }