From 7069f9e7a29406a94b37a8219cae80acd454f8e9 Mon Sep 17 00:00:00 2001 From: overtrue Date: Wed, 28 May 2025 15:29:09 +0800 Subject: [PATCH] fix: resolve all doctest failures in rustfs-obs crate --- crates/obs/src/global.rs | 4 ++-- crates/obs/src/lib.rs | 16 +++++++++++----- crates/obs/src/logger.rs | 16 ++++++++-------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/crates/obs/src/global.rs b/crates/obs/src/global.rs index 07657fb41..0593e0a83 100644 --- a/crates/obs/src/global.rs +++ b/crates/obs/src/global.rs @@ -44,9 +44,9 @@ pub enum GlobalError { /// ```rust /// use rustfs_obs::{init_telemetry, load_config, set_global_guard}; /// -/// async fn init() -> Result<(), Box> { +/// fn init() -> Result<(), Box> { /// let config = load_config(None); -/// let guard = init_telemetry(&config.observability).await?; +/// let guard = init_telemetry(&config.observability); /// set_global_guard(guard)?; /// Ok(()) /// } diff --git a/crates/obs/src/lib.rs b/crates/obs/src/lib.rs index 6a8f6219a..4a25f1b0b 100644 --- a/crates/obs/src/lib.rs +++ b/crates/obs/src/lib.rs @@ -22,11 +22,14 @@ /// /// ## Usage /// -/// ```rust +/// ```no_run /// use rustfs_obs::{AppConfig, init_obs}; /// +/// # #[tokio::main] +/// # async fn main() { /// let config = AppConfig::default(); -/// let (logger, guard) = init_obs(config); +/// let (logger, guard) = init_obs(config).await; +/// # } /// ``` mod config; mod entry; @@ -64,11 +67,14 @@ use tracing::{error, info}; /// A tuple containing the logger and the telemetry guard /// /// # Example -/// ``` +/// ```no_run /// use rustfs_obs::{AppConfig, init_obs}; /// +/// # #[tokio::main] +/// # async fn main() { /// let config = AppConfig::default(); -/// let (logger, guard) = init_obs(config); +/// let (logger, guard) = init_obs(config).await; +/// # } /// ``` pub async fn init_obs(config: AppConfig) -> (Arc>, telemetry::OtelGuard) { let guard = init_telemetry(&config.observability); @@ -97,7 +103,7 @@ pub async fn init_obs(config: AppConfig) -> (Arc>, telemetry::Otel /// A reference to the global logger instance /// /// # Example -/// ``` +/// ```no_run /// use rustfs_obs::get_logger; /// /// let logger = get_logger(); diff --git a/crates/obs/src/logger.rs b/crates/obs/src/logger.rs index 02e0bf9b2..462c2c4cf 100644 --- a/crates/obs/src/logger.rs +++ b/crates/obs/src/logger.rs @@ -224,7 +224,7 @@ impl Logger { /// # Returns /// The global logger instance /// # Example -/// ``` +/// ```no_run /// use rustfs_obs::{AppConfig, start_logger}; /// /// let config = AppConfig::default(); @@ -270,7 +270,7 @@ pub async fn init_global_logger(config: &AppConfig, sinks: Vec>) - /// A reference to the global logger instance /// /// # Example -/// ``` +/// ```no_run /// use rustfs_obs::get_global_logger; /// /// let logger = get_global_logger(); @@ -290,7 +290,7 @@ pub fn get_global_logger() -> &'static Arc> { /// Result indicating whether the operation was successful /// /// # Example -/// ``` +/// ```no_run /// use rustfs_obs::log_info; /// /// async fn example() { @@ -309,7 +309,7 @@ pub async fn log_info(message: &str, source: &str) -> Result<(), GlobalError> { /// # Returns /// Result indicating whether the operation was successful /// # Example -/// ``` +/// ```no_run /// use rustfs_obs::log_error; /// /// async fn example() { @@ -328,7 +328,7 @@ pub async fn log_error(message: &str, source: &str) -> Result<(), GlobalError> { /// Result indicating whether the operation was successful /// /// # Example -/// ``` +/// ```no_run /// use rustfs_obs::log_warn; /// /// async fn example() { @@ -348,7 +348,7 @@ pub async fn log_warn(message: &str, source: &str) -> Result<(), GlobalError> { /// Result indicating whether the operation was successful /// /// # Example -/// ``` +/// ```no_run /// use rustfs_obs::log_debug; /// /// async fn example() { @@ -369,7 +369,7 @@ pub async fn log_debug(message: &str, source: &str) -> Result<(), GlobalError> { /// Result indicating whether the operation was successful /// /// # Example -/// ``` +/// ```no_run /// use rustfs_obs::log_trace; /// /// async fn example() { @@ -392,7 +392,7 @@ pub async fn log_trace(message: &str, source: &str) -> Result<(), GlobalError> { /// # Returns /// Result indicating whether the operation was successful /// # Example -/// ``` +/// ```no_run /// use tracing_core::Level; /// use rustfs_obs::log_with_context; ///