35 lines
1.1 KiB
Rust
35 lines
1.1 KiB
Rust
use tracing_subscriber::layer::SubscriberExt;
|
|
use tracing_subscriber::util::SubscriberInitExt;
|
|
use tracing_subscriber::EnvFilter;
|
|
|
|
pub fn init_telemetry() -> Result<(), Box<dyn std::error::Error>> {
|
|
let env_filter = EnvFilter::try_from_default_env().unwrap_or(EnvFilter::new("WARN"));
|
|
|
|
// let stdout = tracing_subscriber::fmt::Layer::new()
|
|
// .pretty()
|
|
// .with_file(true)
|
|
// .with_line_number(true)
|
|
// .with_thread_ids(false)
|
|
// .with_target(false);
|
|
|
|
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(())
|
|
}
|
|
|
|
pub fn shutdown_telemetry() -> Result<(), Box<dyn std::error::Error>> {
|
|
opentelemetry::global::shutdown_tracer_provider();
|
|
Ok(())
|
|
}
|