mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-29 00:00:11 +02:00
trace: Allow specifying a new span's parent (#923)
This branch allows users of `tokio-trace` to explicitly set a span's parent, or indicate that a span should be a new root of its own trace tree. A `parent: ` key has been added to the `span!` macros. When a span is provided, that span will be set as the parent, while `parent: None` will result in a new root span. No `parent:` key results in the current behaviour. A new type, `span::Attributes`, was added to `tokio-trace-core` to act as an arguments struct for the `Subscriber::new_span` method. This will allow future fields to be added without causing breaking API changes. The `Attributes` struct currently contains the new span's metadata, `ValueSet`, and parent. Finally, the `span::Span` type in `-core` was renamed to `span::Id`, for consistency with `tokio-trace` and to differentiate it from `span::Attributes`. This name was chosen primarily due to precedent in other tracing systems. Closes #920 Signed-off-by: Eliza Weisman <[email protected]>
This commit is contained in:
@@ -77,8 +77,8 @@ impl Subscriber for CounterSubscriber {
|
||||
interest
|
||||
}
|
||||
|
||||
fn new_span(&self, _new_span: &Metadata, values: &field::ValueSet) -> Id {
|
||||
values.record(&mut self.recorder());
|
||||
fn new_span(&self, new_span: &span::Attributes) -> Id {
|
||||
new_span.values().record(&mut self.recorder());
|
||||
let id = self.ids.fetch_add(1, Ordering::SeqCst);
|
||||
Id::from_u64(id as u64)
|
||||
}
|
||||
|
||||
@@ -206,14 +206,12 @@ impl Subscriber for SloggishSubscriber {
|
||||
true
|
||||
}
|
||||
|
||||
fn new_span(
|
||||
&self,
|
||||
span: &tokio_trace::Metadata,
|
||||
values: &tokio_trace::field::ValueSet,
|
||||
) -> tokio_trace::Id {
|
||||
fn new_span(&self, span: &tokio_trace::span::Attributes) -> tokio_trace::Id {
|
||||
let meta = span.metadata();
|
||||
let values = span.values();
|
||||
let next = self.ids.fetch_add(1, Ordering::SeqCst) as u64;
|
||||
let id = tokio_trace::Id::from_u64(next);
|
||||
let span = Span::new(self.current.id(), span, values);
|
||||
let span = Span::new(self.current.id(), meta, values);
|
||||
self.spans.lock().unwrap().insert(id.clone(), span);
|
||||
id
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user