mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-29 00:00:11 +02:00
trace: Add arguments struct to subscriber::Record (#955)
This branch changes the `Subscriber::record` method to take a new arguments struct, `span::Record`. The `field::Record` trait was renamed to `field::Visit` to prevent name conflicts. In addition, the `ValueSet::is_empty`, `ValueSet::contains`, and `ValueSet::record` methods were made crate-private, as they are exposed on the `Attributes` and `Record` types. Signed-off-by: Eliza Weisman <[email protected]>
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
extern crate tokio_trace;
|
||||
|
||||
use tokio_trace::{
|
||||
field::{self, Field, Record},
|
||||
field::{self, Field, Visit},
|
||||
span,
|
||||
subscriber::{self, Subscriber},
|
||||
Event, Id, Metadata,
|
||||
@@ -29,7 +29,7 @@ struct Count<'a> {
|
||||
counters: RwLockReadGuard<'a, HashMap<String, AtomicUsize>>,
|
||||
}
|
||||
|
||||
impl<'a> Record for Count<'a> {
|
||||
impl<'a> Visit for Count<'a> {
|
||||
fn record_i64(&mut self, field: &Field, value: i64) {
|
||||
if let Some(counter) = self.counters.get(field.name()) {
|
||||
if value > 0 {
|
||||
@@ -52,7 +52,7 @@ impl<'a> Record for Count<'a> {
|
||||
}
|
||||
|
||||
impl CounterSubscriber {
|
||||
fn recorder(&self) -> Count {
|
||||
fn visitor(&self) -> Count {
|
||||
Count {
|
||||
counters: self.counters.0.read().unwrap(),
|
||||
}
|
||||
@@ -78,7 +78,7 @@ impl Subscriber for CounterSubscriber {
|
||||
}
|
||||
|
||||
fn new_span(&self, new_span: &span::Attributes) -> Id {
|
||||
new_span.values().record(&mut self.recorder());
|
||||
new_span.record(&mut self.visitor());
|
||||
let id = self.ids.fetch_add(1, Ordering::SeqCst);
|
||||
Id::from_u64(id as u64)
|
||||
}
|
||||
@@ -87,12 +87,12 @@ impl Subscriber for CounterSubscriber {
|
||||
// unimplemented
|
||||
}
|
||||
|
||||
fn record(&self, _: &Id, values: &field::ValueSet) {
|
||||
values.record(&mut self.recorder())
|
||||
fn record(&self, _: &Id, values: &span::Record) {
|
||||
values.record(&mut self.visitor())
|
||||
}
|
||||
|
||||
fn event(&self, event: &Event) {
|
||||
event.record(&mut self.recorder())
|
||||
event.record(&mut self.visitor())
|
||||
}
|
||||
|
||||
fn enabled(&self, metadata: &Metadata) -> bool {
|
||||
|
||||
Reference in New Issue
Block a user