From 2b993f255f95ec57f583896504a1b9d65706f661 Mon Sep 17 00:00:00 2001 From: Amos Wenger Date: Fri, 19 Jul 2024 00:48:38 +0200 Subject: [PATCH] Add rubicon 3.x support --- tracing-core/Cargo.toml | 1 + tracing-core/src/callsite.rs | 20 +++--- tracing-core/src/dispatcher.rs | 56 +++++++++------ tracing-core/src/field.rs | 55 ++++++++------ tracing-core/src/metadata.rs | 4 +- tracing-core/src/subscriber.rs | 30 ++++++++ tracing-flame/Cargo.toml | 1 + tracing-flame/src/lib.rs | 6 +- tracing-log/Cargo.toml | 1 + tracing-log/src/interest_cache.rs | 46 ++++++------ tracing-log/src/lib.rs | 37 ++++++---- tracing-subscriber/Cargo.toml | 1 + tracing-subscriber/src/field/mod.rs | 20 +++--- .../src/filter/env/directive.rs | 72 ++++++++++--------- .../src/filter/layer_filters/mod.rs | 2 +- tracing-subscriber/src/fmt/fmt_layer.rs | 6 +- tracing-subscriber/src/fmt/format/mod.rs | 4 +- tracing-subscriber/src/layer/mod.rs | 4 +- tracing-subscriber/src/registry/sharded.rs | 22 +++--- tracing/Cargo.toml | 1 + tracing/src/lib.rs | 2 + 21 files changed, 239 insertions(+), 152 deletions(-) diff --git a/tracing-core/Cargo.toml b/tracing-core/Cargo.toml index e4f1bed1cd..59bd100452 100644 --- a/tracing-core/Cargo.toml +++ b/tracing-core/Cargo.toml @@ -35,6 +35,7 @@ maintenance = { status = "actively-developed" } [dependencies] once_cell = { version = "1.13.0", optional = true } +rubicon = "3.0.1" [target.'cfg(tracing_unstable)'.dependencies] valuable = { version = "0.1.0", optional = true, default-features = false } diff --git a/tracing-core/src/callsite.rs b/tracing-core/src/callsite.rs index 62fa8c4af6..5e95d9580d 100644 --- a/tracing-core/src/callsite.rs +++ b/tracing-core/src/callsite.rs @@ -254,14 +254,16 @@ pub fn register(callsite: &'static dyn Callsite) { CALLSITES.push_dyn(callsite); } -static CALLSITES: Callsites = Callsites { - list_head: AtomicPtr::new(ptr::null_mut()), - has_locked_callsites: AtomicBool::new(false), -}; +rubicon::process_local! { + static CALLSITES: Callsites = Callsites { + list_head: AtomicPtr::new(ptr::null_mut()), + has_locked_callsites: AtomicBool::new(false), + }; -static DISPATCHERS: Dispatchers = Dispatchers::new(); + static DISPATCHERS: Dispatchers = Dispatchers::new(); -static LOCKED_CALLSITES: Lazy>> = Lazy::new(Default::default); + static LOCKED_CALLSITES: Lazy>> = Lazy::new(Default::default); +} struct Callsites { list_head: AtomicPtr, @@ -526,8 +528,10 @@ mod dispatchers { has_just_one: AtomicBool, } - static LOCKED_DISPATCHERS: Lazy>> = - Lazy::new(Default::default); + rubicon::process_local! { + static LOCKED_DISPATCHERS: Lazy>> = + Lazy::new(Default::default); + } pub(super) enum Rebuilder<'a> { JustOne, diff --git a/tracing-core/src/dispatcher.rs b/tracing-core/src/dispatcher.rs index de02afb790..bf62a6d81c 100644 --- a/tracing-core/src/dispatcher.rs +++ b/tracing-core/src/dispatcher.rs @@ -186,30 +186,34 @@ enum Kind { } #[cfg(feature = "std")] -thread_local! { +rubicon::thread_local! { static CURRENT_STATE: State = State { default: RefCell::new(None), can_enter: Cell::new(true), }; } -static EXISTS: AtomicBool = AtomicBool::new(false); -static GLOBAL_INIT: AtomicUsize = AtomicUsize::new(UNINITIALIZED); +rubicon::process_local! { + static EXISTS: AtomicBool = AtomicBool::new(false); + static GLOBAL_INIT: AtomicUsize = AtomicUsize::new(UNINITIALIZED); -#[cfg(feature = "std")] -static SCOPED_COUNT: AtomicUsize = AtomicUsize::new(0); + #[cfg(feature = "std")] + static SCOPED_COUNT: AtomicUsize = AtomicUsize::new(0); +} const UNINITIALIZED: usize = 0; const INITIALIZING: usize = 1; const INITIALIZED: usize = 2; -static mut GLOBAL_DISPATCH: Dispatch = Dispatch { - subscriber: Kind::Global(&NO_SUBSCRIBER), -}; -static NONE: Dispatch = Dispatch { - subscriber: Kind::Global(&NO_SUBSCRIBER), -}; -static NO_SUBSCRIBER: NoSubscriber = NoSubscriber::new(); +rubicon::process_local! { + static mut GLOBAL_DISPATCH: Dispatch = Dispatch { + subscriber: Kind::Global(&NO_SUBSCRIBER), + }; + static NONE: Dispatch = Dispatch { + subscriber: Kind::Global(&NO_SUBSCRIBER), + }; + static NO_SUBSCRIBER: NoSubscriber = NoSubscriber::new(); +} /// The dispatch state of a thread. #[cfg(feature = "std")] @@ -929,15 +933,17 @@ mod test { } struct TestCallsite; - static TEST_CALLSITE: TestCallsite = TestCallsite; - static TEST_META: Metadata<'static> = metadata! { - name: "test", - target: module_path!(), - level: Level::DEBUG, - fields: &[], - callsite: &TEST_CALLSITE, - kind: Kind::EVENT - }; + rubicon::process_local! { + static TEST_CALLSITE: TestCallsite = TestCallsite; + static TEST_META: Metadata<'static> = metadata! { + name: "test", + target: module_path!(), + level: Level::DEBUG, + fields: &[], + callsite: &TEST_CALLSITE, + kind: Kind::EVENT + }; + } impl Callsite for TestCallsite { fn set_interest(&self, _: Interest) {} @@ -966,7 +972,9 @@ mod test { fn record_follows_from(&self, _: &span::Id, _: &span::Id) {} fn event(&self, _: &Event<'_>) { - static EVENTS: AtomicUsize = AtomicUsize::new(0); + rubicon::process_local! { + static EVENTS: AtomicUsize = AtomicUsize::new(0); + } assert_eq!( EVENTS.fetch_add(1, Ordering::Relaxed), 0, @@ -1007,7 +1015,9 @@ mod test { } fn new_span(&self, _: &span::Attributes<'_>) -> span::Id { - static NEW_SPANS: AtomicUsize = AtomicUsize::new(0); + rubicon::process_local! { + static NEW_SPANS: AtomicUsize = AtomicUsize::new(0); + } assert_eq!( NEW_SPANS.fetch_add(1, Ordering::Relaxed), 0, diff --git a/tracing-core/src/field.rs b/tracing-core/src/field.rs index 90c4eaa85d..4f486be572 100644 --- a/tracing-core/src/field.rs +++ b/tracing-core/src/field.rs @@ -640,7 +640,9 @@ impl fmt::Debug for dyn Value { // We are only going to be recording the field value, so we don't // actually care about the field name here. struct NullCallsite; - static NULL_CALLSITE: NullCallsite = NullCallsite; + rubicon::process_local! { + static NULL_CALLSITE: NullCallsite = NullCallsite; + } impl crate::callsite::Callsite for NullCallsite { fn set_interest(&self, _: crate::subscriber::Interest) { unreachable!("you somehow managed to register the null callsite?") @@ -651,10 +653,12 @@ impl fmt::Debug for dyn Value { } } - static FIELD: Field = Field { - i: 0, - fields: FieldSet::new(&[], crate::identify_callsite!(&NULL_CALLSITE)), - }; + rubicon::process_local! { + static FIELD: Field = Field { + i: 0, + fields: FieldSet::new(&[], crate::identify_callsite!(&NULL_CALLSITE)), + }; + } let mut res = Ok(()); self.record(&FIELD, &mut |_: &Field, val: &dyn fmt::Debug| { @@ -1091,15 +1095,18 @@ mod test { // Make sure TEST_CALLSITE_* have non-zero size, so they can't be located at the same address. struct TestCallsite1(u8); - static TEST_CALLSITE_1: TestCallsite1 = TestCallsite1(0); - static TEST_META_1: Metadata<'static> = metadata! { - name: "field_test1", - target: module_path!(), - level: Level::INFO, - fields: &["foo", "bar", "baz"], - callsite: &TEST_CALLSITE_1, - kind: Kind::SPAN, - }; + + rubicon::process_local! { + static TEST_CALLSITE_1: TestCallsite1 = TestCallsite1(0); + static TEST_META_1: Metadata<'static> = metadata! { + name: "field_test1", + target: module_path!(), + level: Level::INFO, + fields: &["foo", "bar", "baz"], + callsite: &TEST_CALLSITE_1, + kind: Kind::SPAN, + }; + } impl crate::callsite::Callsite for TestCallsite1 { fn set_interest(&self, _: crate::subscriber::Interest) { @@ -1112,15 +1119,17 @@ mod test { } struct TestCallsite2(u8); - static TEST_CALLSITE_2: TestCallsite2 = TestCallsite2(0); - static TEST_META_2: Metadata<'static> = metadata! { - name: "field_test2", - target: module_path!(), - level: Level::INFO, - fields: &["foo", "bar", "baz"], - callsite: &TEST_CALLSITE_2, - kind: Kind::SPAN, - }; + rubicon::process_local! { + static TEST_CALLSITE_2: TestCallsite2 = TestCallsite2(0); + static TEST_META_2: Metadata<'static> = metadata! { + name: "field_test2", + target: module_path!(), + level: Level::INFO, + fields: &["foo", "bar", "baz"], + callsite: &TEST_CALLSITE_2, + kind: Kind::SPAN, + }; + } impl crate::callsite::Callsite for TestCallsite2 { fn set_interest(&self, _: crate::subscriber::Interest) { diff --git a/tracing-core/src/metadata.rs b/tracing-core/src/metadata.rs index 7d8448b641..3ddec37541 100644 --- a/tracing-core/src/metadata.rs +++ b/tracing-core/src/metadata.rs @@ -242,7 +242,9 @@ pub struct LevelFilter(Option); #[derive(Clone, Debug)] pub struct ParseLevelFilterError(()); -static MAX_LEVEL: AtomicUsize = AtomicUsize::new(LevelFilter::OFF_USIZE); +rubicon::process_local! { + static MAX_LEVEL: AtomicUsize = AtomicUsize::new(LevelFilter::OFF_USIZE); +} // ===== impl Metadata ===== diff --git a/tracing-core/src/subscriber.rs b/tracing-core/src/subscriber.rs index 17b6316971..a98cdf1e6e 100644 --- a/tracing-core/src/subscriber.rs +++ b/tracing-core/src/subscriber.rs @@ -699,6 +699,36 @@ impl Subscriber for NoSubscriber { fn exit(&self, _span: &span::Id) {} } +impl Subscriber for rubicon::TrustedExtern { + fn enabled(&self, metadata: &Metadata<'_>) -> bool { + self.0.enabled(metadata) + } + + fn new_span(&self, span: &span::Attributes<'_>) -> span::Id { + self.0.new_span(span) + } + + fn record(&self, span: &span::Id, values: &span::Record<'_>) { + self.0.record(span, values) + } + + fn record_follows_from(&self, span: &span::Id, follows: &span::Id) { + self.0.record_follows_from(span, follows) + } + + fn event(&self, event: &Event<'_>) { + self.0.event(event) + } + + fn enter(&self, span: &span::Id) { + self.0.enter(span) + } + + fn exit(&self, span: &span::Id) { + self.0.exit(span) + } +} + impl NoSubscriber { /// Returns a new `NoSubscriber`. #[must_use] diff --git a/tracing-flame/Cargo.toml b/tracing-flame/Cargo.toml index 81ea126cfa..ade44fa6f9 100644 --- a/tracing-flame/Cargo.toml +++ b/tracing-flame/Cargo.toml @@ -29,6 +29,7 @@ smallvec = ["tracing-subscriber/smallvec"] tracing-subscriber = { path = "../tracing-subscriber", version = "0.3.0", default-features = false, features = ["registry", "fmt"] } tracing = { path = "../tracing", version = "0.1.35", default-features = false, features = ["std"] } once_cell = "1.13.0" +rubicon = "3.0.1" [dev-dependencies] diff --git a/tracing-flame/src/lib.rs b/tracing-flame/src/lib.rs index 6ae2e19a3e..063b195bb0 100644 --- a/tracing-flame/src/lib.rs +++ b/tracing-flame/src/lib.rs @@ -157,9 +157,11 @@ use tracing_subscriber::Layer; mod error; -static START: Lazy = Lazy::new(Instant::now); +rubicon::process_local! { + static START: Lazy = Lazy::new(Instant::now); +} -thread_local! { +rubicon::thread_local! { static LAST_EVENT: Cell = Cell::new(*START); static THREAD_NAME: String = { diff --git a/tracing-log/Cargo.toml b/tracing-log/Cargo.toml index dad4cf366d..eea7347917 100644 --- a/tracing-log/Cargo.toml +++ b/tracing-log/Cargo.toml @@ -29,6 +29,7 @@ log = { version = "0.4.17" } once_cell = "1.13.0" lru = { version = "0.7.7", optional = true } ahash = { version = "0.7.7", optional = true } +rubicon = "3.0.1" [dev-dependencies] tracing = { path = "../tracing", version = "0.1.35"} diff --git a/tracing-log/src/interest_cache.rs b/tracing-log/src/interest_cache.rs index aabf9ebaf7..89877e2d0c 100644 --- a/tracing-log/src/interest_cache.rs +++ b/tracing-log/src/interest_cache.rs @@ -111,7 +111,9 @@ impl State { // like and whether subscribers will actually be interested in it, since nothing will actually // be logged from it. -static INTEREST_CACHE_EPOCH: AtomicUsize = AtomicUsize::new(0); +rubicon::process_local! { + static INTEREST_CACHE_EPOCH: AtomicUsize = AtomicUsize::new(0); +} fn interest_cache_epoch() -> usize { INTEREST_CACHE_EPOCH.load(Ordering::Relaxed) @@ -129,24 +131,26 @@ impl tracing_core::Callsite for SentinelCallsite { } } -static SENTINEL_CALLSITE: SentinelCallsite = SentinelCallsite; -static SENTINEL_METADATA: tracing_core::Metadata<'static> = tracing_core::Metadata::new( - "log interest cache", - "log", - tracing_core::Level::ERROR, - None, - None, - None, - tracing_core::field::FieldSet::new(&[], tracing_core::identify_callsite!(&SENTINEL_CALLSITE)), - tracing_core::metadata::Kind::EVENT, -); - -static CONFIG: Lazy> = Lazy::new(|| { - tracing_core::callsite::register(&SENTINEL_CALLSITE); - Mutex::new(InterestCacheConfig::disabled()) -}); - -thread_local! { +rubicon::process_local! { + static SENTINEL_CALLSITE: SentinelCallsite = SentinelCallsite; + static SENTINEL_METADATA: tracing_core::Metadata<'static> = tracing_core::Metadata::new( + "log interest cache", + "log", + tracing_core::Level::ERROR, + None, + None, + None, + tracing_core::field::FieldSet::new(&[], tracing_core::identify_callsite!(&SENTINEL_CALLSITE)), + tracing_core::metadata::Kind::EVENT, + ); + + static CONFIG: Lazy> = Lazy::new(|| { + tracing_core::callsite::register(&SENTINEL_CALLSITE); + Mutex::new(InterestCacheConfig::disabled()) + }); +} + +rubicon::thread_local! { static STATE: RefCell = { let config = CONFIG.lock().unwrap(); RefCell::new(State::new(interest_cache_epoch(), &config)) @@ -235,7 +239,9 @@ mod tests { fn lock_for_test() -> impl Drop { // We need to make sure only one test runs at a time. - static LOCK: Lazy> = Lazy::new(Mutex::new); + rubicon::process_local! { + static LOCK: Lazy> = Lazy::new(Mutex::new); + } match LOCK.lock() { Ok(guard) => guard, diff --git a/tracing-log/src/lib.rs b/tracing-log/src/lib.rs index be896f1624..19231a8ad6 100644 --- a/tracing-log/src/lib.rs +++ b/tracing-log/src/lib.rs @@ -123,6 +123,8 @@ )] use once_cell::sync::Lazy; +pub use rubicon; + use std::{fmt, io}; use tracing_core::{ @@ -250,6 +252,7 @@ struct Fields { line: field::Field, } +// rubicon safety: this one can be duplicated across shared objects, it's fine. static FIELD_NAMES: &[&str] = &[ "message", "log.target", @@ -280,16 +283,18 @@ macro_rules! log_cs { ($level:expr, $cs:ident, $meta:ident, $ty:ident) => { struct $ty; static $cs: $ty = $ty; - static $meta: Metadata<'static> = Metadata::new( - "log event", - "log", - $level, - ::core::option::Option::None, - ::core::option::Option::None, - ::core::option::Option::None, - field::FieldSet::new(FIELD_NAMES, identify_callsite!(&$cs)), - Kind::EVENT, - ); + $crate::rubicon::process_local! { + static $meta: Metadata<'static> = Metadata::new( + "log event", + "log", + $level, + ::core::option::Option::None, + ::core::option::Option::None, + ::core::option::Option::None, + field::FieldSet::new(FIELD_NAMES, identify_callsite!(&$cs)), + Kind::EVENT, + ); + } impl callsite::Callsite for $ty { fn set_interest(&self, _: subscriber::Interest) {} @@ -321,11 +326,13 @@ log_cs!( ErrorCallsite ); -static TRACE_FIELDS: Lazy = Lazy::new(|| Fields::new(&TRACE_CS)); -static DEBUG_FIELDS: Lazy = Lazy::new(|| Fields::new(&DEBUG_CS)); -static INFO_FIELDS: Lazy = Lazy::new(|| Fields::new(&INFO_CS)); -static WARN_FIELDS: Lazy = Lazy::new(|| Fields::new(&WARN_CS)); -static ERROR_FIELDS: Lazy = Lazy::new(|| Fields::new(&ERROR_CS)); +rubicon::process_local! { + static TRACE_FIELDS: Lazy = Lazy::new(|| Fields::new(&TRACE_CS)); + static DEBUG_FIELDS: Lazy = Lazy::new(|| Fields::new(&DEBUG_CS)); + static INFO_FIELDS: Lazy = Lazy::new(|| Fields::new(&INFO_CS)); + static WARN_FIELDS: Lazy = Lazy::new(|| Fields::new(&WARN_CS)); + static ERROR_FIELDS: Lazy = Lazy::new(|| Fields::new(&ERROR_CS)); +} fn level_to_cs(level: Level) -> (&'static dyn Callsite, &'static Fields) { match level { diff --git a/tracing-subscriber/Cargo.toml b/tracing-subscriber/Cargo.toml index 807880b8cd..9692ed0584 100644 --- a/tracing-subscriber/Cargo.toml +++ b/tracing-subscriber/Cargo.toml @@ -64,6 +64,7 @@ chrono = { version = "0.4.26", default-features = false, features = ["clock", "s # registry sharded-slab = { version = "0.1.4", optional = true } thread_local = { version = "1.1.4", optional = true } +rubicon = "3.0.1" [target.'cfg(tracing_unstable)'.dependencies] valuable_crate = { package = "valuable", version = "0.1.0", optional = true, default-features = false } diff --git a/tracing-subscriber/src/field/mod.rs b/tracing-subscriber/src/field/mod.rs index 03b9146ba6..8f36d2bf6b 100644 --- a/tracing-subscriber/src/field/mod.rs +++ b/tracing-subscriber/src/field/mod.rs @@ -303,15 +303,17 @@ pub(in crate::field) mod test_util { } struct TestCallsite1; - static TEST_CALLSITE_1: &'static dyn Callsite = &TestCallsite1; - static TEST_META_1: Metadata<'static> = tracing_core::metadata! { - name: "field_test1", - target: module_path!(), - level: Level::INFO, - fields: &["question", "question.answer", "tricky", "can_you_do_it"], - callsite: TEST_CALLSITE_1, - kind: Kind::SPAN, - }; + rubicon::process_local! { + static TEST_CALLSITE_1: &'static dyn Callsite = &TestCallsite1; + static TEST_META_1: Metadata<'static> = tracing_core::metadata! { + name: "field_test1", + target: module_path!(), + level: Level::INFO, + fields: &["question", "question.answer", "tricky", "can_you_do_it"], + callsite: TEST_CALLSITE_1, + kind: Kind::SPAN, + }; + } impl Callsite for TestCallsite1 { fn set_interest(&self, _: tracing_core::subscriber::Interest) { diff --git a/tracing-subscriber/src/filter/env/directive.rs b/tracing-subscriber/src/filter/env/directive.rs index d095065f88..b6ea168337 100644 --- a/tracing-subscriber/src/filter/env/directive.rs +++ b/tracing-subscriber/src/filter/env/directive.rs @@ -120,46 +120,48 @@ impl Directive { } pub(super) fn parse(from: &str, regex: bool) -> Result { - static DIRECTIVE_RE: Lazy = Lazy::new(|| { - Regex::new( - r"(?x) - ^(?P(?i:trace|debug|info|warn|error|off|[0-5]))$ | - # ^^^. - # `note: we match log level names case-insensitively - ^ - (?: # target name or span name - (?P[\w:-]+)|(?P\[[^\]]*\]) - ){1,2} - (?: # level or nothing - =(?P(?i:trace|debug|info|warn|error|off|[0-5]))? - # ^^^. - # `note: we match log level names case-insensitively - )? - $ - ", - ) - .unwrap() - }); - static SPAN_PART_RE: Lazy = - Lazy::new(|| Regex::new(r"(?P[^\]\{]+)?(?:\{(?P[^\}]*)\})?").unwrap()); - static FIELD_FILTER_RE: Lazy = - // TODO(eliza): this doesn't _currently_ handle value matchers that include comma - // characters. We should fix that. - Lazy::new(|| { + rubicon::process_local! { + static DIRECTIVE_RE: Lazy = Lazy::new(|| { Regex::new( r"(?x) - ( - # field name - [[:word:]][[[:word:]]\.]* - # value part (optional) - (?:=[^,]+)? - ) - # trailing comma or EOS - (?:,\s?|$) - ", + ^(?P(?i:trace|debug|info|warn|error|off|[0-5]))$ | + # ^^^. + # `note: we match log level names case-insensitively + ^ + (?: # target name or span name + (?P[\w:-]+)|(?P\[[^\]]*\]) + ){1,2} + (?: # level or nothing + =(?P(?i:trace|debug|info|warn|error|off|[0-5]))? + # ^^^. + # `note: we match log level names case-insensitively + )? + $ + ", ) .unwrap() }); + static SPAN_PART_RE: Lazy = + Lazy::new(|| Regex::new(r"(?P[^\]\{]+)?(?:\{(?P[^\}]*)\})?").unwrap()); + static FIELD_FILTER_RE: Lazy = + // TODO(eliza): this doesn't _currently_ handle value matchers that include comma + // characters. We should fix that. + Lazy::new(|| { + Regex::new( + r"(?x) + ( + # field name + [[:word:]][[[:word:]]\.]* + # value part (optional) + (?:=[^,]+)? + ) + # trailing comma or EOS + (?:,\s?|$) + ", + ) + .unwrap() + }); + } let caps = DIRECTIVE_RE.captures(from).ok_or_else(ParseError::new)?; diff --git a/tracing-subscriber/src/filter/layer_filters/mod.rs b/tracing-subscriber/src/filter/layer_filters/mod.rs index 69736fafd4..9fe040a2a2 100644 --- a/tracing-subscriber/src/filter/layer_filters/mod.rs +++ b/tracing-subscriber/src/filter/layer_filters/mod.rs @@ -156,7 +156,7 @@ struct DebugCounters { in_interest_pass: Cell, } -thread_local! { +rubicon::thread_local! { pub(crate) static FILTERING: FilterState = FilterState::new(); } diff --git a/tracing-subscriber/src/fmt/fmt_layer.rs b/tracing-subscriber/src/fmt/fmt_layer.rs index d3cb8c1ed5..6427bc7991 100644 --- a/tracing-subscriber/src/fmt/fmt_layer.rs +++ b/tracing-subscriber/src/fmt/fmt_layer.rs @@ -942,11 +942,11 @@ where } fn on_event(&self, event: &Event<'_>, ctx: Context<'_, S>) { - thread_local! { - static BUF: RefCell = RefCell::new(String::new()); + rubicon::thread_local! { + static TRACING_SUBSCRIBER_FMT_LAYER_BUF: RefCell = RefCell::new(String::new()); } - BUF.with(|buf| { + TRACING_SUBSCRIBER_FMT_LAYER_BUF.with(|buf| { let borrow = buf.try_borrow_mut(); let mut a; let mut b; diff --git a/tracing-subscriber/src/fmt/format/mod.rs b/tracing-subscriber/src/fmt/format/mod.rs index 80612e1ec2..b155ff3bab 100644 --- a/tracing-subscriber/src/fmt/format/mod.rs +++ b/tracing-subscriber/src/fmt/format/mod.rs @@ -1436,7 +1436,9 @@ impl<'a> fmt::Display for FmtThreadName<'a> { // Track the longest thread name length we've seen so far in an atomic, // so that it can be updated by any thread. - static MAX_LEN: AtomicUsize = AtomicUsize::new(0); + rubicon::process_local! { + static MAX_LEN: AtomicUsize = AtomicUsize::new(0); + } let len = self.name.len(); // Snapshot the current max thread name length. let mut max_len = MAX_LEN.load(Relaxed); diff --git a/tracing-subscriber/src/layer/mod.rs b/tracing-subscriber/src/layer/mod.rs index 296de5ef48..f7c4f54f20 100644 --- a/tracing-subscriber/src/layer/mod.rs +++ b/tracing-subscriber/src/layer/mod.rs @@ -1517,7 +1517,9 @@ pub struct Identity { #[derive(Clone, Copy)] pub(crate) struct NoneLayerMarker(()); -static NONE_LAYER_MARKER: NoneLayerMarker = NoneLayerMarker(()); +rubicon::process_local! { + static NONE_LAYER_MARKER: NoneLayerMarker = NoneLayerMarker(()); +} /// Is a type implementing `Layer` `Option::<_>::None`? pub(crate) fn layer_is_none(layer: &L) -> bool diff --git a/tracing-subscriber/src/registry/sharded.rs b/tracing-subscriber/src/registry/sharded.rs index 88520a2a66..164930822c 100644 --- a/tracing-subscriber/src/registry/sharded.rs +++ b/tracing-subscriber/src/registry/sharded.rs @@ -209,7 +209,7 @@ impl Registry { } } -thread_local! { +rubicon::thread_local! { /// `CLOSE_COUNT` is the thread-local counter used by `CloseGuard` to /// track how many layers have processed the close. /// For additional details, see [`CloseGuard`]. @@ -470,15 +470,17 @@ impl Default for DataInner { } } - static NULL_CALLSITE: NullCallsite = NullCallsite; - static NULL_METADATA: Metadata<'static> = tracing_core::metadata! { - name: "", - target: "", - level: tracing_core::Level::TRACE, - fields: &[], - callsite: &NULL_CALLSITE, - kind: tracing_core::metadata::Kind::SPAN, - }; + rubicon::process_local! { + static NULL_CALLSITE: NullCallsite = NullCallsite; + static NULL_METADATA: Metadata<'static> = tracing_core::metadata! { + name: "", + target: "", + level: tracing_core::Level::TRACE, + fields: &[], + callsite: &NULL_CALLSITE, + kind: tracing_core::metadata::Kind::SPAN, + }; + } Self { filter_map: FilterMap::default(), diff --git a/tracing/Cargo.toml b/tracing/Cargo.toml index bcad05c640..5b2e037f48 100644 --- a/tracing/Cargo.toml +++ b/tracing/Cargo.toml @@ -32,6 +32,7 @@ tracing-core = { path = "../tracing-core", version = "0.1.32", default-features log = { version = "0.4.17", optional = true } tracing-attributes = { path = "../tracing-attributes", version = "0.1.27", optional = true } pin-project-lite = "0.2.9" +rubicon = "3.0.1" [dev-dependencies] criterion = { version = "0.3.6", default_features = false } diff --git a/tracing/src/lib.rs b/tracing/src/lib.rs index b3db75a64d..f9a44f04ca 100644 --- a/tracing/src/lib.rs +++ b/tracing/src/lib.rs @@ -948,6 +948,8 @@ extern crate alloc; #[doc(hidden)] use tracing_core::*; +pub use rubicon; + #[doc(inline)] pub use self::instrument::Instrument; pub use self::{dispatcher::Dispatch, event::Event, field::Value, subscriber::Subscriber};