From 258eaa48cea51fc4d205ff4469d93367320c0cec Mon Sep 17 00:00:00 2001 From: Caleb Schoepp Date: Tue, 14 May 2024 15:14:38 -0600 Subject: [PATCH] Use spin_telemetry instead of our own subscriber Signed-off-by: Caleb Schoepp --- Cargo.lock | 14 +------------- Cargo.toml | 2 +- src/main.rs | 19 +++++++++++++------ 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 83e53e9..ff5a786 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5388,17 +5388,6 @@ dependencies = [ "valuable", ] -[[package]] -name = "tracing-log" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" -dependencies = [ - "log", - "once_cell", - "tracing-core", -] - [[package]] name = "tracing-opentelemetry" version = "0.23.0" @@ -5443,7 +5432,6 @@ dependencies = [ "thread_local", "tracing", "tracing-core", - "tracing-log", "tracing-serde", ] @@ -5458,10 +5446,10 @@ dependencies = [ "serde", "spin-app", "spin-core", + "spin-telemetry", "spin-trigger", "tokio", "tracing", - "tracing-subscriber", "wasmtime-wasi", ] diff --git a/Cargo.toml b/Cargo.toml index 5f3a86f..c1da75a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,9 +20,9 @@ serde = "1.0" spin-app = { git = "https://github.com/fermyon/spin", tag = "v2.5.1" } spin-core = { git = "https://github.com/fermyon/spin", tag = "v2.5.1" } spin-trigger = { git = "https://github.com/fermyon/spin", tag = "v2.5.1" } +spin-telemetry = { git = "https://github.com/fermyon/spin", tag = "v2.5.1" } tokio = { version = "1.23", features = ["full"] } tracing = { version = "0.1", features = ["log"] } -tracing-subscriber = { version = "0.3.7", features = ["env-filter"] } wasmtime-wasi = { version = "18.0.4", features = ["tokio"] } [target.'cfg(target_os = "linux")'.dependencies] diff --git a/src/main.rs b/src/main.rs index 965d6f0..975588a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,18 +1,25 @@ use clap::Parser; use spin_trigger::cli::TriggerExecutorCommand; -use std::io::IsTerminal; use trigger_command::CommandTrigger; type Command = TriggerExecutorCommand; #[tokio::main] async fn main() -> anyhow::Result<()> { - tracing_subscriber::fmt() - .with_writer(std::io::stderr) - .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) - .with_ansi(std::io::stderr().is_terminal()) - .init(); + let _telemetry_guard = spin_telemetry::init(build_info())?; let t = Command::parse(); t.run().await } + +/// Returns build information of the parent Spin process, similar to: 0.1.0 (2be4034 2022-03-31). +fn build_info() -> String { + let spin_version = env_var("SPIN_VERSION"); + let spin_commit_sha = env_var("SPIN_COMMIT_SHA"); + let spin_commit_date = env_var("SPIN_COMMIT_DATE"); + format!("{spin_version} ({spin_commit_sha} {spin_commit_date})") +} + +fn env_var(name: &str) -> String { + std::env::var(name).unwrap_or_else(|_| "unknown".to_string()) +}