diff --git a/Cargo.lock b/Cargo.lock index db913f6c00..5a17c96e96 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2799,6 +2799,7 @@ dependencies = [ "rustc-hash", "serde", "serde_json", + "serde_path_to_error", "strum", "time", "tokio", diff --git a/crates/router_env/Cargo.toml b/crates/router_env/Cargo.toml index d9fb1518a0..82615bc2e6 100644 --- a/crates/router_env/Cargo.toml +++ b/crates/router_env/Cargo.toml @@ -17,6 +17,7 @@ opentelemetry-otlp = { git = "https://github.com/open-telemetry/opentelemetry-ru rustc-hash = "1.1" serde = { version = "1.0.149", features = ["derive"] } serde_json = "1.0.89" +serde_path_to_error = "0.1.8" strum = { version = "0.24.1", features = ["derive"] } time = { version = "0.3.17", default-features = false, features = ["formatting"] } tokio = { version = "1.23.0" } diff --git a/crates/router_env/README.md b/crates/router_env/README.md index 1812281241..6108585645 100644 --- a/crates/router_env/README.md +++ b/crates/router_env/README.md @@ -22,8 +22,6 @@ pub fn sample() -> () { ## Files Tree Layout - - ```text ├── src : source code │ └── logger : logger diff --git a/crates/router_env/src/logger/config.rs b/crates/router_env/src/logger/config.rs index 114fad0933..a823aef47b 100644 --- a/crates/router_env/src/logger/config.rs +++ b/crates/router_env/src/logger/config.rs @@ -115,22 +115,15 @@ impl Config { let environment = crate::env::which(); let config_path = Self::config_path(&environment.to_string(), explicit_config_path); - // println!( - // "config_path : {:?} {:?}", - // config_path, - // std::path::Path::new(&config_path).exists() - // ); - let config = Self::builder(&environment.to_string())? .add_source(config::File::from(config_path).required(true)) .add_source(config::Environment::with_prefix("ROUTER").separator("__")) .build()?; - // FIXME: in case config is missing information about error is not readable - config.try_deserialize().map_err(|e| { - crate::error!("Unable to source config file"); - eprintln!("Unable to source config file"); - e + serde_path_to_error::deserialize(config).map_err(|error| { + crate::error!(%error, "Unable to deserialize configuration"); + eprintln!("Unable to deserialize application configuration: {error}"); + error.into_inner() }) } @@ -144,6 +137,7 @@ impl Config { // Should be single source of truth. .set_override("env", environment)? .add_source(config::File::from_str( + // Plan on handling with the changes in crates/router // FIXME: embedding of textual file into bin files has several disadvantages // 1. larger bin file // 2. slower initialization of program diff --git a/crates/router_env/src/logger/formatter.rs b/crates/router_env/src/logger/formatter.rs index 11d9abc66b..cc66fccfe4 100644 --- a/crates/router_env/src/logger/formatter.rs +++ b/crates/router_env/src/logger/formatter.rs @@ -22,8 +22,7 @@ use tracing_subscriber::{ }; use crate::Storage; - -// FIXME: xxx: Describe each implicit field with examples. +// TODO: Documentation coverage for this crate // Implicit keys @@ -52,14 +51,6 @@ const REQUEST_METHOD: &str = "request_method"; const REQUEST_URL_PATH: &str = "request_url_path"; const REQUEST_ID: &str = "request_id"; -//const TAG: &str = "tag"; -//const CATEGORY: &str = "category"; -//const SESSION_ID: &str = "session_id"; -//const PAYMENT_ID: &str = "payment_id"; -//const PAYMENT_ATTEMPT_ID: &str = "payment_attempt_id"; -//const MERCHANT_ID: &str = "merchant_id"; -//const FLOW: &str = "flow"; - /// Set of predefined implicit keys. pub static IMPLICIT_KEYS: Lazy> = Lazy::new(|| { let mut set = rustc_hash::FxHashSet::default(); diff --git a/crates/router_env/src/logger/macros.rs b/crates/router_env/src/logger/macros.rs deleted file mode 100644 index c3398e98c6..0000000000 --- a/crates/router_env/src/logger/macros.rs +++ /dev/null @@ -1,104 +0,0 @@ -//! -//! Macros. -//! - -pub use crate::log; - -/// -/// Make a new log Event. -/// -/// The event macro is invoked with a Level and up to 32 key-value fields. -/// Optionally, a format string and arguments may follow the fields; this will be used to construct an implicit field named “message”. -/// See the top-level [documentation of tracing](https://docs.rs/tracing/latest/tracing/index.html#using-the-macros) for details on the syntax accepted by this macro. -/// -/// # Example -/// ```rust -/// // FIXME: write -/// ``` -/// - -#[macro_export] -macro_rules! log { - - // done - - ( - @MUNCH - { - level : { $level:ident }, - tag : { $tag:ident }, - category : { $category:ident }, - flow : { $flow:expr }, - // $( session_id : { $session_id:expr }, )? - // $( payment_id : { $payment_id:expr }, )? - // $( payment_attempt_id : { $payment_attempt_id:expr }, )? - // $( merchant_id : { $merchant_id:expr }, )? - }, - $( $tail:tt )* - ) - => - ( - ::tracing::event! - ( - ::router_env::Level::$level, - level = ?::router_env::Level::$level, - tag = ?::router_env::Tag::$tag, - category = ?::router_env::Category::$category, - flow = ?$flow, - // $( session_id = $session_id, )? - // $( payment_id = $payment_id, )? - // $( payment_attempt_id = $payment_attempt_id, )? - // $( merchant_id = $merchant_id, )? - $( $tail )* - ); - ); - - // entry with colon - - ( - level : $level:ident, - tag : $tag:ident, - category : $category:ident, - flow : $(?)?$flow:expr, - $( $tail:tt )* - ) - => - ( - $crate::log! - { - @MUNCH - { - level : { $level }, - tag : { $tag }, - category : { $category }, - flow : { $flow }, - }, - $( $tail )* - } - ); - - // entry without colon - - ( - $level:ident, - $tag:ident, - $category:ident, - $flow:expr, - $( $tail:tt )* - ) - => - ( - $crate::log! - { - @MUNCH - { - level : { $level }, - tag : { $tag }, - category : { $category }, - flow : { $flow }, - }, - $( $tail )* - } - ); - -} diff --git a/crates/router_env/src/logger/setup.rs b/crates/router_env/src/logger/setup.rs index 4ba3bbc342..e2970b3be1 100644 --- a/crates/router_env/src/logger/setup.rs +++ b/crates/router_env/src/logger/setup.rs @@ -22,30 +22,6 @@ use tracing_subscriber::{ use crate::{config, FormattingLayer, Level, StorageSubscription}; -// FIXME: xxx: clean -pub struct DebugLayer; -impl Layer for DebugLayer -where - S: tracing::Subscriber, -{ - fn on_event( - &self, - event: &tracing::Event<'_>, - _ctx: tracing_subscriber::layer::Context<'_, S>, - ) { - if event.metadata().level() == &Level::TRACE { - return; - } - println!("Got event!"); - println!(" level={:?}", event.metadata().level()); - println!(" target={:?}", event.metadata().target()); - println!(" name={:?}", event.metadata().name()); - for field in event.fields() { - println!(" field={}", field.name()); - } - } -} - /// TelemetryGuard which helps with #[derive(Debug)] pub struct TelemetryGuard {