Skip to content

Commit 96424d0

Browse files
authored
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 <[email protected]>
1 parent db986fc commit 96424d0

File tree

11 files changed

+19
-15
lines changed

11 files changed

+19
-15
lines changed

tracing-fmt/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ default = ["ansi", "chrono"]
99
ansi = ["ansi_term"]
1010

1111
[dependencies]
12-
tracing-core = "0.1"
12+
tracing-core = "0.1.2"
1313
ansi_term = { version = "0.11", optional = true }
1414
regex = "1"
1515
lazy_static = "1"

tracing-fmt/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ where
206206
id.clone()
207207
}
208208

209-
fn drop_span(&self, id: span::Id) {
210-
self.spans.drop_span(id);
209+
fn try_close(&self, id: span::Id) -> bool {
210+
self.spans.drop_span(id)
211211
}
212212

213213
unsafe fn downcast_raw(&self, id: TypeId) -> Option<*const ()> {

tracing-fmt/src/span.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub(crate) fn pop(expected_id: &Id) {
101101
.and_then(|i| i);
102102
if id.is_some() {
103103
dispatcher::get_default(|subscriber| {
104-
subscriber.drop_span(id.take().unwrap());
104+
let _ = subscriber.try_close(id.take().unwrap());
105105
})
106106
}
107107
}
@@ -349,7 +349,7 @@ impl Store {
349349
/// removes the span if it is zero.
350350
///
351351
/// The allocated span slot will be reused when a new span is created.
352-
pub fn drop_span(&self, id: Id) {
352+
pub fn drop_span(&self, id: Id) -> bool {
353353
let this = self.inner.read();
354354
let idx = id_to_idx(&id);
355355

@@ -359,14 +359,15 @@ impl Store {
359359
.map(|span| span.read().drop_ref())
360360
.unwrap_or(false)
361361
{
362-
return;
362+
return false;
363363
}
364364

365365
// Synchronize only if we are actually removing the span (stolen
366366
// from std::Arc);
367367
atomic::fence(Ordering::Acquire);
368368

369369
this.remove(&self.next, idx);
370+
true
370371
}
371372
}
372373

@@ -397,7 +398,7 @@ impl Drop for Data {
397398
if self.parent.is_some() {
398399
dispatcher::get_default(|subscriber| {
399400
if let Some(parent) = self.parent.take() {
400-
subscriber.drop_span(parent);
401+
let _ = subscriber.try_close(parent);
401402
}
402403
})
403404
}

tracing-futures/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ tokio-executor = { version = "0.1", optional = true }
1616
[dev-dependencies]
1717
tokio = "0.1.22"
1818
tracing-fmt = { path = "../tracing-fmt" }
19-
tracing-core = "0.1"
19+
tracing-core = "0.1.2"

tracing-log/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ authors = ["Eliza Weisman <[email protected]>"]
55
edition = "2018"
66

77
[dependencies]
8-
tracing-core = "0.1"
8+
tracing-core = "0.1.2"
99
tracing-subscriber = { path = "../tracing-subscriber" }
1010
log = "0.4"
1111
lazy_static = "1.3.0"

tracing-log/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,19 +579,20 @@ impl Subscriber for TraceLogger {
579579
id.clone()
580580
}
581581

582-
fn drop_span(&self, id: Id) {
582+
fn try_close(&self, id: Id) -> bool {
583583
let mut spans = self.spans.lock().unwrap();
584584
if spans.contains_key(&id) {
585585
if spans.get(&id).unwrap().ref_count == 1 {
586586
let span = spans.remove(&id).unwrap();
587587
if self.settings.log_span_closes {
588588
span.finish();
589589
}
590+
return true;
590591
} else {
591592
spans.get_mut(&id).unwrap().ref_count -= 1;
592593
}
593-
return;
594594
}
595+
false
595596
}
596597
}
597598

tracing-serde/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2018"
77

88
[dependencies]
99
serde = "1"
10-
tracing-core = "0.1"
10+
tracing-core = "0.1.2"
1111

1212
[dev-dependencies]
1313
serde_json = "1.0"

tracing/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ keywords = ["logging", "tracing"]
2727
edition = "2018"
2828

2929
[dependencies]
30-
tracing-core = "0.1.1"
30+
tracing-core = "0.1.2"
3131
log = { version = "0.4", optional = true }
3232
cfg-if = "0.1.9"
3333

tracing/examples/sloggish/sloggish_subscriber.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ impl Subscriber for SloggishSubscriber {
279279
self.current.exit();
280280
}
281281

282-
fn drop_span(&self, _id: tracing::Id) {
282+
fn try_close(&self, _id: tracing::Id) -> bool {
283283
// TODO: GC unneeded spans.
284+
false
284285
}
285286
}

tracing/src/span.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ impl Hash for Inner {
884884

885885
impl Drop for Inner {
886886
fn drop(&mut self) {
887-
self.subscriber.drop_span(self.id.clone());
887+
let _ = self.subscriber.try_close(self.id.clone());
888888
}
889889
}
890890

tracing/tests/support/subscriber.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ where
8181
self
8282
}
8383

84+
#[allow(deprecated)]
8485
pub fn drop_span(mut self, span: MockSpan) -> Self {
8586
self.expected.push_back(Expect::DropSpan(span));
8687
self

0 commit comments

Comments
 (0)