From 6b5f68ced900a4324576049b3b617ae0f2fd3958 Mon Sep 17 00:00:00 2001 From: "Zhidong Peng (HE/HIM)" Date: Mon, 8 Sep 2025 12:26:12 -0700 Subject: [PATCH] Remove backtrace crate as it has perf concern. --- Cargo.lock | 1 - proxy_agent/src/common/logger.rs | 6 +- proxy_agent/src/proxy/proxy_connection.rs | 7 +- proxy_agent_shared/Cargo.toml | 1 - proxy_agent_shared/src/logger.rs | 81 ----------------------- 5 files changed, 4 insertions(+), 92 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a72dcfb3..f07e20dc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -879,7 +879,6 @@ dependencies = [ name = "proxy_agent_shared" version = "9.9.9" dependencies = [ - "backtrace", "chrono", "concurrent-queue", "ctor", diff --git a/proxy_agent/src/common/logger.rs b/proxy_agent/src/common/logger.rs index a3e06819..437a3f69 100644 --- a/proxy_agent/src/common/logger.rs +++ b/proxy_agent/src/common/logger.rs @@ -29,13 +29,11 @@ fn log(log_level: LoggerLevel, message: String) { if let Some(log_for_event) = config::get_file_log_level_for_events() { if log_for_event >= log_level { // write to event - let (module_name, caller_name) = - proxy_agent_shared::logger::get_caller_info("proxy_agent::common::logger"); event_logger::write_event_only( log_level, message.to_string(), - &caller_name, - &module_name, + "CommonLogger", + "ProxyAgent", ); } } diff --git a/proxy_agent/src/proxy/proxy_connection.rs b/proxy_agent/src/proxy/proxy_connection.rs index b4200251..0e1802fd 100644 --- a/proxy_agent/src/proxy/proxy_connection.rs +++ b/proxy_agent/src/proxy/proxy_connection.rs @@ -300,14 +300,11 @@ impl ConnectionLogger { if let Some(log_for_event) = crate::common::config::get_file_log_level_for_events() { if log_for_event >= logger_level { // write to event - let (module_name, caller_name) = proxy_agent_shared::logger::get_caller_info( - "proxy_agent::proxy::proxy_connection", - ); proxy_agent_shared::telemetry::event_logger::write_event_only( logger_level, message.to_string(), - &caller_name, - &module_name, + "ConnectionLogger", + "ProxyAgent", ); } } diff --git a/proxy_agent_shared/Cargo.toml b/proxy_agent_shared/Cargo.toml index 4de75911..f3f4e353 100644 --- a/proxy_agent_shared/Cargo.toml +++ b/proxy_agent_shared/Cargo.toml @@ -18,7 +18,6 @@ thiserror = "1.0.64" tokio = { version = "1", features = ["rt", "macros", "sync", "time"] } log = { version = "0.4.26", features = ["std"] } ctor = "0.3.6" # used for test setup and clean up -backtrace = "0.3" # used for get the caller module and function name [target.'cfg(windows)'.dependencies] windows-service = "0.7.0" # windows NT service diff --git a/proxy_agent_shared/src/logger.rs b/proxy_agent_shared/src/logger.rs index 6b9a305e..e5933f00 100644 --- a/proxy_agent_shared/src/logger.rs +++ b/proxy_agent_shared/src/logger.rs @@ -35,74 +35,6 @@ fn get_log_header_with_length( header } -const ASYNC_FUNCTION_NAME: &str = "{closure"; -const INTERNAL_BACKTRACE: &str = "backtrace"; -const CURRENT_FUNCTION: &str = "::logger::get_caller_info"; -const RUNTIME_TASK_SCHEDULER: &str = "::runtime::task::Schedule"; // The runtime scheduler function that runs the tasks -const TOKIO_RUNTIME_SCHEDULER: &str = "::runtime::scheduler"; // The runtime scheduler function that runs the tasks, found in command `cargo llvm-cov --target x86_64-unknown-linux-musl` with rust-1.88.0 - -#[cfg(test)] -const TEST_CODE_COVERAGE_FUNCTIONS: &str = "__covrec_"; // code coverage recording, generated by a code coverage tool such as llvm-cov, or a similar instrumentation framework -#[cfg(test)] -const TEST_INTERNAL_FUNCTION: &str = "test::run_test"; // The test framework's internal function that runs the tests - -pub fn get_caller_info(module_to_skip: &str) -> (String, String) { - let bt = backtrace::Backtrace::new(); - - for frame in bt.frames().iter() { - for symbol in frame.symbols() { - if let Some(name) = symbol.name() { - let name_str = name.to_string(); - - let mut found_function: bool = true; - // Skip internal frames, current function frame and `module_to_skip` to find the first relevant caller - found_function = found_function - && !name_str.contains(INTERNAL_BACKTRACE) - && !name_str.contains(CURRENT_FUNCTION) - && !name_str.contains(RUNTIME_TASK_SCHEDULER) - && !name_str.contains(TOKIO_RUNTIME_SCHEDULER) - && !name_str.contains(module_to_skip); - - #[cfg(test)] - { - found_function = found_function - && !name_str.contains(TEST_CODE_COVERAGE_FUNCTIONS) - && !name_str.starts_with(TEST_INTERNAL_FUNCTION); - } - - if found_function { - // If the name contains `{{closure}}`, it indicates an async function - // We need to find the first segment that contains the async function name - // Example: `azure_proxy_agent::proxy::proxy_server::ProxyServer::handle_new_tcp_connection::{{closure}}::{{closure}}::h537d19fb7a504d22` - let seg = name_str.split("::").collect::>(); - let seg_len = seg.len(); - let mut function_last_index = 0; - for i in 0..seg_len { - if seg[seg_len - 1 - i].contains(ASYNC_FUNCTION_NAME) { - function_last_index = i + 1; - } - } - let caller_name = seg - .get(seg_len - 1 - function_last_index) - .unwrap_or(&"unknown") - .to_string(); - // Get the module name from the first to `function_last_index` segment - let module_name = seg - .into_iter() - .map(String::from) - .collect::>() - .into_iter() - .take(seg_len - 1 - function_last_index) - .collect::>() - .join("::"); - return (module_name, caller_name); - } - } - } - } - ("unknown".to_string(), "unknown".to_string()) -} - #[cfg(test)] mod tests { use log::Level; @@ -126,19 +58,6 @@ mod tests { ); } - #[tokio::test] - async fn invoke_get_caller_info_test() { - test_get_caller_info_test("invoke_get_caller_info_test"); - } - - fn test_get_caller_info_test(expected_caller_name: &str) { - let (module_name, caller_name) = super::get_caller_info("test_get_caller_info_test"); - println!("Module Name: {}", module_name); - println!("Caller Name: {}", caller_name); - // Check if the caller name is as expected - assert_eq!(caller_name, expected_caller_name); - } - #[test] fn get_log_header_with_length_test() { let header = super::get_log_header_with_length(