From f3f143aaf2dbc9382f89df90d624f6ad34d2b97e Mon Sep 17 00:00:00 2001 From: Ryan Butler Date: Wed, 11 Dec 2024 14:01:22 -0600 Subject: [PATCH] refactor(attest): switch to orb-telemetry (#319) --- Cargo.lock | 1 + attest/Cargo.toml | 1 + attest/src/lib.rs | 5 ++-- attest/src/logging.rs | 61 ---------------------------------------- attest/src/main.rs | 3 ++ attest/src/remote_api.rs | 2 +- 6 files changed, 8 insertions(+), 65 deletions(-) delete mode 100644 attest/src/logging.rs diff --git a/Cargo.lock b/Cargo.lock index b298e355..43039619 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4346,6 +4346,7 @@ dependencies = [ "orb-build-info 0.0.0", "orb-const-concat 0.0.0", "orb-security-utils", + "orb-telemetry", "reqwest", "ring 0.16.20", "secrecy", diff --git a/attest/Cargo.toml b/attest/Cargo.toml index 9233e766..b17d2d6a 100644 --- a/attest/Cargo.toml +++ b/attest/Cargo.toml @@ -20,6 +20,7 @@ orb-attest-dbus.workspace = true orb-build-info.workspace = true orb-const-concat.workspace = true orb-security-utils = { workspace = true, features = ["reqwest"] } +orb-telemetry.workspace = true reqwest = { workspace = true, features = ["json", "multipart"] } ring.workspace = true secrecy = { workspace = true, features = ["serde"] } diff --git a/attest/src/lib.rs b/attest/src/lib.rs index cc6c4428..0bf43399 100644 --- a/attest/src/lib.rs +++ b/attest/src/lib.rs @@ -3,7 +3,6 @@ pub mod client; pub mod config; pub mod dbus; -pub mod logging; pub mod remote_api; use std::sync::Arc; @@ -20,10 +19,10 @@ const BUILD_INFO: BuildInfo = make_build_info!(); const HTTP_RETRY_DELAY: std::time::Duration = std::time::Duration::from_secs(3); +pub const SYSLOG_IDENTIFIER: &str = "worldcoin-attest"; + #[allow(clippy::missing_errors_doc)] pub async fn main() -> eyre::Result<()> { - logging::init(); - info!("Version: {}", BUILD_INFO.version); let orb_id = diff --git a/attest/src/logging.rs b/attest/src/logging.rs deleted file mode 100644 index 4e201a45..00000000 --- a/attest/src/logging.rs +++ /dev/null @@ -1,61 +0,0 @@ -use std::io::IsTerminal; - -use eyre::{self, WrapErr}; -use tracing::warn; -use tracing_subscriber::{ - self, - filter::{EnvFilter, LevelFilter}, - prelude::*, - Layer, -}; - -const SYSLOG_IDENTIFIER: &str = "worldcoin-attest"; - -fn try_init_journal() -> eyre::Result<()> { - let journal = tracing_journald::layer() - .wrap_err("Failed to initialize journald logger")? - .with_syslog_identifier(SYSLOG_IDENTIFIER.to_owned()); - tracing_subscriber::registry().with(journal).try_init()?; - Ok(()) -} - -fn try_init_stdout_logger() -> eyre::Result<()> { - let filter = EnvFilter::builder() - .with_default_directive(LevelFilter::INFO.into()) - .from_env_lossy(); - - let stdout_log = tracing_subscriber::fmt::layer() - .compact() - .with_writer(std::io::stdout) - .with_filter(filter); - let stderr_log = tracing_subscriber::fmt::layer() - .compact() - .with_writer(std::io::stderr); - - tracing_subscriber::registry() - .with( - stderr_log - .with_filter(LevelFilter::WARN) - .and_then(stdout_log), - ) - .try_init()?; - - Ok(()) -} - -/// Initialize the logger -pub fn init() { - let mut err: Option = None; - let istty = std::io::stdin().is_terminal(); - if !istty { - err = try_init_journal().err(); - } - - if istty || err.is_some() { - err = try_init_stdout_logger().err(); - } - - if let Some(e) = err { - warn!("failed to initialize journald logger: {}", e); - } -} diff --git a/attest/src/main.rs b/attest/src/main.rs index c9c80a90..c19bbd83 100644 --- a/attest/src/main.rs +++ b/attest/src/main.rs @@ -1,5 +1,8 @@ #[tokio::main] async fn main() -> color_eyre::Result<()> { color_eyre::install()?; + orb_telemetry::TelemetryConfig::new() + .with_journald(orb_attest::SYSLOG_IDENTIFIER) + .init(); orb_attest::main().await } diff --git a/attest/src/remote_api.rs b/attest/src/remote_api.rs index c7df6cae..a346241f 100644 --- a/attest/src/remote_api.rs +++ b/attest/src/remote_api.rs @@ -518,7 +518,7 @@ printf dmFsaWRzaWduYXR1cmU= // A happy path #[tokio::test] async fn get_token() { - crate::logging::init(); + orb_telemetry::TelemetryConfig::new().init(); let mock_server = MockServer::start().await;