mirror of
https://github.com/tokio-rs/tracing.git
synced 2025-09-28 21:42:15 +00:00
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 <eliza@buoyant.io>
This commit is contained in:
parent
db986fce66
commit
96424d04a1
@ -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"
|
||||
|
@ -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 ()> {
|
||||
|
@ -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);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -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"
|
||||
|
@ -5,7 +5,7 @@ authors = ["Eliza Weisman <eliza@buoyant.io>"]
|
||||
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"
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
serde = "1"
|
||||
tracing-core = "0.1"
|
||||
tracing-core = "0.1.2"
|
||||
|
||||
[dev-dependencies]
|
||||
serde_json = "1.0"
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user