From 96424d04a1ba49cbb90cf3dd91cfab0aa3ca2bd1 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Thu, 11 Jul 2019 11:56:04 -0700 Subject: [PATCH] chore: update everything to use `try_close` (#174) ## Motivation `tracing-core` 0.1.2 deprecated the `Subscriber::drop_span` function in favour of `try_close`. ## Solution This branch updates all other crates to depend on core 0.1.2, and replaces uses of `drop_span` with `try_close`. Signed-off-by: Eliza Weisman --- tracing-fmt/Cargo.toml | 2 +- tracing-fmt/src/lib.rs | 4 ++-- tracing-fmt/src/span.rs | 9 +++++---- tracing-futures/Cargo.toml | 2 +- tracing-log/Cargo.toml | 2 +- tracing-log/src/lib.rs | 5 +++-- tracing-serde/Cargo.toml | 2 +- tracing/Cargo.toml | 2 +- tracing/examples/sloggish/sloggish_subscriber.rs | 3 ++- tracing/src/span.rs | 2 +- tracing/tests/support/subscriber.rs | 1 + 11 files changed, 19 insertions(+), 15 deletions(-) diff --git a/tracing-fmt/Cargo.toml b/tracing-fmt/Cargo.toml index 21aa803c..0a0215a3 100644 --- a/tracing-fmt/Cargo.toml +++ b/tracing-fmt/Cargo.toml @@ -9,7 +9,7 @@ default = ["ansi", "chrono"] ansi = ["ansi_term"] [dependencies] -tracing-core = "0.1" +tracing-core = "0.1.2" ansi_term = { version = "0.11", optional = true } regex = "1" lazy_static = "1" diff --git a/tracing-fmt/src/lib.rs b/tracing-fmt/src/lib.rs index cf3d533e..f40535ad 100644 --- a/tracing-fmt/src/lib.rs +++ b/tracing-fmt/src/lib.rs @@ -206,8 +206,8 @@ where id.clone() } - fn drop_span(&self, id: span::Id) { - self.spans.drop_span(id); + fn try_close(&self, id: span::Id) -> bool { + self.spans.drop_span(id) } unsafe fn downcast_raw(&self, id: TypeId) -> Option<*const ()> { diff --git a/tracing-fmt/src/span.rs b/tracing-fmt/src/span.rs index 25fae697..88b04495 100644 --- a/tracing-fmt/src/span.rs +++ b/tracing-fmt/src/span.rs @@ -101,7 +101,7 @@ pub(crate) fn pop(expected_id: &Id) { .and_then(|i| i); if id.is_some() { dispatcher::get_default(|subscriber| { - subscriber.drop_span(id.take().unwrap()); + let _ = subscriber.try_close(id.take().unwrap()); }) } } @@ -349,7 +349,7 @@ impl Store { /// removes the span if it is zero. /// /// The allocated span slot will be reused when a new span is created. - pub fn drop_span(&self, id: Id) { + pub fn drop_span(&self, id: Id) -> bool { let this = self.inner.read(); let idx = id_to_idx(&id); @@ -359,7 +359,7 @@ impl Store { .map(|span| span.read().drop_ref()) .unwrap_or(false) { - return; + return false; } // Synchronize only if we are actually removing the span (stolen @@ -367,6 +367,7 @@ impl Store { atomic::fence(Ordering::Acquire); this.remove(&self.next, idx); + true } } @@ -397,7 +398,7 @@ impl Drop for Data { if self.parent.is_some() { dispatcher::get_default(|subscriber| { if let Some(parent) = self.parent.take() { - subscriber.drop_span(parent); + let _ = subscriber.try_close(parent); } }) } diff --git a/tracing-futures/Cargo.toml b/tracing-futures/Cargo.toml index 791e3a49..264e54d8 100644 --- a/tracing-futures/Cargo.toml +++ b/tracing-futures/Cargo.toml @@ -16,4 +16,4 @@ tokio-executor = { version = "0.1", optional = true } [dev-dependencies] tokio = "0.1.22" tracing-fmt = { path = "../tracing-fmt" } -tracing-core = "0.1" +tracing-core = "0.1.2" diff --git a/tracing-log/Cargo.toml b/tracing-log/Cargo.toml index 5cf924ed..b99470a6 100644 --- a/tracing-log/Cargo.toml +++ b/tracing-log/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Eliza Weisman "] edition = "2018" [dependencies] -tracing-core = "0.1" +tracing-core = "0.1.2" tracing-subscriber = { path = "../tracing-subscriber" } log = "0.4" lazy_static = "1.3.0" diff --git a/tracing-log/src/lib.rs b/tracing-log/src/lib.rs index dfb66395..dff87c49 100644 --- a/tracing-log/src/lib.rs +++ b/tracing-log/src/lib.rs @@ -579,7 +579,7 @@ impl Subscriber for TraceLogger { id.clone() } - fn drop_span(&self, id: Id) { + fn try_close(&self, id: Id) -> bool { let mut spans = self.spans.lock().unwrap(); if spans.contains_key(&id) { if spans.get(&id).unwrap().ref_count == 1 { @@ -587,11 +587,12 @@ impl Subscriber for TraceLogger { if self.settings.log_span_closes { span.finish(); } + return true; } else { spans.get_mut(&id).unwrap().ref_count -= 1; } - return; } + false } } diff --git a/tracing-serde/Cargo.toml b/tracing-serde/Cargo.toml index cb806fbf..f2980759 100644 --- a/tracing-serde/Cargo.toml +++ b/tracing-serde/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] serde = "1" -tracing-core = "0.1" +tracing-core = "0.1.2" [dev-dependencies] serde_json = "1.0" diff --git a/tracing/Cargo.toml b/tracing/Cargo.toml index c30365c1..f11aaadc 100644 --- a/tracing/Cargo.toml +++ b/tracing/Cargo.toml @@ -27,7 +27,7 @@ keywords = ["logging", "tracing"] edition = "2018" [dependencies] -tracing-core = "0.1.1" +tracing-core = "0.1.2" log = { version = "0.4", optional = true } cfg-if = "0.1.9" diff --git a/tracing/examples/sloggish/sloggish_subscriber.rs b/tracing/examples/sloggish/sloggish_subscriber.rs index 7a484b4b..72f22327 100644 --- a/tracing/examples/sloggish/sloggish_subscriber.rs +++ b/tracing/examples/sloggish/sloggish_subscriber.rs @@ -279,7 +279,8 @@ impl Subscriber for SloggishSubscriber { self.current.exit(); } - fn drop_span(&self, _id: tracing::Id) { + fn try_close(&self, _id: tracing::Id) -> bool { // TODO: GC unneeded spans. + false } } diff --git a/tracing/src/span.rs b/tracing/src/span.rs index 2b392508..4e56df48 100644 --- a/tracing/src/span.rs +++ b/tracing/src/span.rs @@ -884,7 +884,7 @@ impl Hash for Inner { impl Drop for Inner { fn drop(&mut self) { - self.subscriber.drop_span(self.id.clone()); + let _ = self.subscriber.try_close(self.id.clone()); } } diff --git a/tracing/tests/support/subscriber.rs b/tracing/tests/support/subscriber.rs index f2bfa5de..6b4dd488 100644 --- a/tracing/tests/support/subscriber.rs +++ b/tracing/tests/support/subscriber.rs @@ -81,6 +81,7 @@ where self } + #[allow(deprecated)] pub fn drop_span(mut self, span: MockSpan) -> Self { self.expected.push_back(Expect::DropSpan(span)); self