Skip to content

Commit

Permalink
Migrate layer crates to use SpanRef::scope
Browse files Browse the repository at this point in the history
  • Loading branch information
nightkr committed Jun 9, 2021
1 parent 84afb38 commit 9ec8130
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
3 changes: 1 addition & 2 deletions tracing-error/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ where
let span = subscriber
.span(id)
.expect("registry should have a span for the current ID");
let parents = span.parents();
for span in std::iter::once(span).chain(parents) {
for span in span.scope().from_root() {
let cont = if let Some(fields) = span.extensions().get::<FormattedFields<F>>() {
f(span.metadata(), fields.fields.as_str())
} else {
Expand Down
20 changes: 8 additions & 12 deletions tracing-flame/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,10 @@ where

let first = ctx.span(id).expect("expected: span id exists in registry");

if !self.config.empty_samples && first.from_root().count() == 0 {
if !self.config.empty_samples && first.parent().is_none() {
return;
}

let parents = first.from_root();

let mut stack = String::new();

if !self.config.threads_collapsed {
Expand All @@ -412,7 +410,11 @@ where
stack += "all-threads";
}

for parent in parents {
let mut parents = first.scope();
parents
.next()
.expect("expected: scope begins with leaf scope");
for parent in parents.from_root() {
stack += "; ";
write(&mut stack, parent, &self.config).expect("expected: write to String never fails");
}
Expand Down Expand Up @@ -444,28 +446,22 @@ where

let samples = self.time_since_last_event();
let first = expect!(ctx.span(&id), "expected: span id exists in registry");
let parents = first.from_root();

let mut stack = String::new();
if !self.config.threads_collapsed {
THREAD_NAME.with(|name| stack += name.as_str());
} else {
stack += "all-threads";
}
stack += "; ";

for parent in parents {
for parent in first.scope().from_root() {
stack += "; ";
expect!(
write(&mut stack, parent, &self.config),
"expected: write to String never fails"
);
stack += "; ";
}

expect!(
write(&mut stack, first, &self.config),
"expected: write to String never fails"
);
expect!(
write!(&mut stack, " {}", samples.as_nanos()),
"expected: write to String never fails"
Expand Down
10 changes: 7 additions & 3 deletions tracing-journald/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ where
let span = ctx.span(id).expect("unknown span");
let mut buf = Vec::with_capacity(256);

let depth = span.parents().count();
let depth = span.scope().skip(1).count();

writeln!(buf, "S{}_NAME", depth).unwrap();
put_value(&mut buf, span.name().as_bytes());
Expand All @@ -143,7 +143,7 @@ where

fn on_record(&self, id: &Id, values: &Record, ctx: Context<S>) {
let span = ctx.span(id).expect("unknown span");
let depth = span.parents().count();
let depth = span.scope().skip(1).count();
let mut exts = span.extensions_mut();
let buf = &mut exts.get_mut::<SpanFields>().expect("missing fields").0;
values.record(&mut SpanVisitor {
Expand All @@ -157,7 +157,11 @@ where
let mut buf = Vec::with_capacity(256);

// Record span fields
for span in ctx.scope() {
for span in ctx
.lookup_current()
.into_iter()
.flat_map(|span| span.scope())
{
let exts = span.extensions();
let fields = exts.get::<SpanFields>().expect("missing fields");
buf.extend_from_slice(&fields.0);
Expand Down

0 comments on commit 9ec8130

Please sign in to comment.