tracing-kickstart
Rust module used to bootstrap tracing and reduce code duplication across projects.
Intended for personal use only.
Example
This example loads the TracingConfig from a .env file by deserializing through a nested config struct.
Example .env file:
APP__TRACE__LOG_FILE_PATH="/tmp/tracing-kickstart-example.log"
APP__TRACE__COLLECTOR_URL="https://otel.example.com:4318"
APP__TRACE__COLLECTOR_AUTH_HEADER="Basic aHVudGVyMg=="
APP__TRACE__ANSI_OUTPUT=true
Implementation example
use config::{Config, Environment};
use dotenvy::dotenv;
use serde::Deserialize;
use tracing_kickstart::TracingConfig;
#[derive(Debug, Clone, Deserialize)]
pub struct Conf {
trace: TracingConfig,
}
#[tokio::main]
async fn main() {
dotenv().ok(); let settings = Config::builder()
.add_source(Environment::with_prefix("APP").separator("__").try_parsing(true))
.build()
.unwrap();
let conf = settings.try_deserialize::<Conf>().unwrap();
let attrs = tracing_kickstart::build_attrs!();
attrs.dump();
let custom_fallback_env_filter = None;
let tracing_providers = tracing_kickstart::init(attrs, &conf.trace, custom_fallback_env_filter).unwrap();
tracing_providers.register_globally(); tracing::info!(?conf.trace, "Tracing initialized");
println!("very important work");
tracing::debug!("Shutting down tracing providers: {tracing_providers:?}");
tracing_providers.shutdown();
}