Skip to content

Commit cc504ce

Browse files
committed
chore: lazy_entry => deferred_spans
1 parent d551f42 commit cc504ce

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

examples/basic.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ fn main() {
1010
.with_thread_names(true)
1111
.with_thread_ids(true)
1212
.with_verbose_exit(true)
13-
.with_verbose_entry(true)
13+
.with_verbose_entry(false)
14+
.with_span_modes(true)
1415
.with_targets(true);
1516

1617
let subscriber = Registry::default().with(layer);

examples/concurrent.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn main() {
1919
.with_verbose_exit(true)
2020
.with_verbose_entry(true)
2121
.with_verbose_retrace(true)
22-
.with_lazy_entry(true)
22+
.with_deferred_spans(true)
2323
.with_targets(true);
2424

2525
let subscriber = Registry::default().with(layer);

src/format.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub struct Config {
5757
/// Whether to print squiggly brackets (`{}`) around the list of fields in a span.
5858
pub bracketed_fields: bool,
5959

60-
pub lazy_entry: bool,
60+
pub deferred_spans: bool,
6161

6262
pub span_modes: bool,
6363
}
@@ -117,9 +117,9 @@ impl Config {
117117
}
118118
}
119119

120-
pub fn with_lazy_entry(self, enable: bool) -> Self {
120+
pub fn with_deferred_spans(self, enable: bool) -> Self {
121121
Self {
122-
lazy_entry: enable,
122+
deferred_spans: enable,
123123
..self
124124
}
125125
}
@@ -175,7 +175,7 @@ impl Default for Config {
175175
verbose_exit: false,
176176
verbose_retrace: false,
177177
bracketed_fields: false,
178-
lazy_entry: false,
178+
deferred_spans: false,
179179
span_modes: false,
180180
}
181181
}

src/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,12 @@ where
211211
}
212212
}
213213

214-
pub fn with_lazy_entry(self, enabled: bool) -> Self {
214+
/// Defers printing span opening until an event is generated within the span.
215+
///
216+
/// Avoids printing empty spans with no generated events.
217+
pub fn with_deferred_spans(self, enabled: bool) -> Self {
215218
Self {
216-
config: self.config.with_lazy_entry(enabled),
219+
config: self.config.with_deferred_spans(enabled),
217220
..self
218221
}
219222
}
@@ -353,12 +356,12 @@ where
353356
let span = ctx.span(id).expect("in new_span but span does not exist");
354357

355358
if span.extensions().get::<Data>().is_none() {
356-
let data = Data::new(attrs, !self.config.lazy_entry);
359+
let data = Data::new(attrs, !self.config.deferred_spans);
357360
span.extensions_mut().insert(data);
358361
}
359362

360363
// Entry will be printed in on_event along with retrace
361-
if self.config.lazy_entry {
364+
if self.config.deferred_spans {
362365
return;
363366
}
364367

@@ -541,7 +544,7 @@ where
541544
let span = ctx.span(&id);
542545

543546
// Span was not printed, so don't print an exit
544-
if self.config.lazy_entry
547+
if self.config.deferred_spans
545548
&& span
546549
.as_ref()
547550
.and_then(|v| v.extensions().get::<Data>().map(|v| v.printed))

0 commit comments

Comments
 (0)