From bc5f31b3a2daa942227386b588047484e753ebcf Mon Sep 17 00:00:00 2001 From: Olivia Lee Date: Sat, 14 Dec 2024 01:01:32 -0800 Subject: [PATCH] add observability prelude module The reason to do a wildcard import of the prelude instead of something like // src/observability/prelude.rs pub(crate) use tracing::*; // elsewhere use crate::observability::prelude as o; o::warn!("something"); is that we can't import traits like tracing::Instrument that way. I'm generally not a fan of wildcard imports, but I think it can be okay when it's a module in the same crate. There aren't really an backwards compatibility hazards because it's your own code. --- src/observability.rs | 2 ++ src/observability/prelude.rs | 14 ++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 src/observability/prelude.rs diff --git a/src/observability.rs b/src/observability.rs index 44e06c91..9f3bca7a 100644 --- a/src/observability.rs +++ b/src/observability.rs @@ -38,6 +38,8 @@ use crate::{ utils::error::Result, }; +pub(crate) mod prelude; + /// Globally accessible metrics state pub(crate) static METRICS: LazyLock = LazyLock::new(Metrics::new); diff --git a/src/observability/prelude.rs b/src/observability/prelude.rs new file mode 100644 index 00000000..63d39bca --- /dev/null +++ b/src/observability/prelude.rs @@ -0,0 +1,14 @@ +//! Common tracing-related items intended to be wildcard imported in most +//! modules: +//! +//! ``` +//! use crate::observability::prelude::*; +//! ``` +//! +//! This avoids diff churn in the imports when adding/removing log statements. +//! +//! [`tracing`] is re-exported as `t`, to avoid name collisions. +#![allow(unused)] + +pub(crate) use tracing as t; +pub(crate) use tracing::Instrument;