Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Lok <[email protected]>
  • Loading branch information
andylokandy committed Jul 17, 2023
1 parent 56af3d8 commit 1e219f1
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions minitrace/examples/get_started.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2022 TiKV Project Authors. Licensed under Apache-2.0.

use minitrace::collector::Config;
use minitrace::collector::TerminalReporter;
use minitrace::collector::ConsoleReporter;
use minitrace::prelude::*;

fn main() {
minitrace::set_reporter(TerminalReporter, Config::default());
minitrace::set_reporter(ConsoleReporter, Config::default());

{
let parent = SpanContext::new(TraceId(rand::random()), SpanId::default());
Expand Down
4 changes: 2 additions & 2 deletions minitrace/examples/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use log::info;
use log_derive::logfn;
use log_derive::logfn_inputs;
use minitrace::collector::Config;
use minitrace::collector::TerminalReporter;
use minitrace::collector::ConsoleReporter;
use minitrace::prelude::*;
use minitrace::Event;

Expand All @@ -18,7 +18,7 @@ fn plus(a: u64, b: u64) -> Result<u64, std::io::Error> {
}

fn main() {
minitrace::set_reporter(TerminalReporter, Config::default());
minitrace::set_reporter(ConsoleReporter, Config::default());
env_logger::Builder::from_default_env()
.format(|buf, record| {
// Add a event to the current local span representing the log record
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
use super::global_collector::Reporter;
use super::SpanRecord;

pub struct TerminalReporter;
pub struct ConsoleReporter;

impl Reporter for TerminalReporter {
impl Reporter for ConsoleReporter {
fn report(&mut self, spans: &[SpanRecord]) -> Result<(), Box<dyn std::error::Error>> {
for span in spans {
eprintln!("{:#?}", span);
Expand Down
18 changes: 9 additions & 9 deletions minitrace/src/collector/global_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ impl GlobalCollector {
let drop_collects = &mut self.drop_collects;
let commit_collects = &mut self.commit_collects;
let submit_spans = &mut self.submit_spans;
let committed_records = &mut self.committed_records;

self.rxs.retain_mut(|rx| {
loop {
Expand Down Expand Up @@ -294,23 +295,23 @@ impl GlobalCollector {
&raw_span,
trace_id,
parent_id,
&mut self.committed_records,
committed_records,
&mut events,
&anchor,
),
SpanSet::LocalSpans(local_spans) => amend_local_span(
&local_spans,
trace_id,
parent_id,
&mut self.committed_records,
committed_records,
&mut events,
&anchor,
),
SpanSet::SharedLocalSpans(local_spans) => amend_local_span(
&local_spans,
trace_id,
parent_id,
&mut self.committed_records,
committed_records,
&mut events,
&anchor,
),
Expand All @@ -324,39 +325,38 @@ impl GlobalCollector {
raw_span,
trace_id,
parent_id,
&mut self.committed_records,
committed_records,
&mut events,
&anchor,
),
SpanSet::LocalSpans(local_spans) => amend_local_span(
local_spans,
trace_id,
parent_id,
&mut self.committed_records,
committed_records,
&mut events,
&anchor,
),
SpanSet::SharedLocalSpans(local_spans) => amend_local_span(
local_spans,
trace_id,
parent_id,
&mut self.committed_records,
committed_records,
&mut events,
&anchor,
),
},
}
}

mount_events(&mut self.committed_records, events);
mount_events(committed_records, events);
}
}

let reporter = self.reporter.as_mut().unwrap();
if let Err(err) = reporter.report(&self.committed_records) {
if let Err(err) = reporter.report(committed_records.drain(..).as_slice()) {
error!("report spans failed: {}", err);
}
self.committed_records.clear();
}
}

Expand Down
8 changes: 4 additions & 4 deletions minitrace/src/collector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
#![cfg_attr(test, allow(dead_code))]

pub(crate) mod command;
mod console_reporter;
pub(crate) mod global_collector;
pub(crate) mod id;
mod terminal_reporter;
mod test_reporter;

use std::rc::Rc;
use std::sync::Arc;

#[cfg(feature = "report")]
pub use console_reporter::ConsoleReporter;
#[cfg(not(test))]
pub(crate) use global_collector::GlobalCollect;
#[cfg(test)]
Expand All @@ -21,8 +23,6 @@ pub(crate) use global_collector::MockGlobalCollect;
pub use global_collector::Reporter;
pub use id::SpanId;
pub use id::TraceId;
#[cfg(feature = "report")]
pub use terminal_reporter::TerminalReporter;
#[doc(hidden)]
pub use test_reporter::TestReporter;

Expand Down Expand Up @@ -183,7 +183,7 @@ impl Config {
/// use minitrace::prelude::*;
///
/// let config = Config::default().max_span_count(Some(100));
/// minitrace::set_reporter(minitrace::collector::TerminalReporter, config);
/// minitrace::set_reporter(minitrace::collector::ConsoleReporter, config);
/// ```
pub fn max_span_count(self, max_span_count: Option<usize>) -> Self {
Self { max_span_count }
Expand Down
20 changes: 10 additions & 10 deletions minitrace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
//!
//! ```
//! use minitrace::prelude::*;
//! use minitrace::collector::TerminalReporter;
//! use minitrace::collector::ConsoleReporter;
//! use minitrace::collector::Config;
//!
//! minitrace::set_reporter(TerminalReporter, Config::default());
//! minitrace::set_reporter(ConsoleReporter, Config::default());
//!
//! {
//! let root = Span::root("root", SpanContext::new(TraceId(12), SpanId::default()));
Expand All @@ -52,10 +52,10 @@
//!
//! ```
//! use minitrace::prelude::*;
//! use minitrace::collector::TerminalReporter;
//! use minitrace::collector::ConsoleReporter;
//! use minitrace::collector::Config;
//!
//! minitrace::set_reporter(TerminalReporter, Config::default());
//! minitrace::set_reporter(ConsoleReporter, Config::default());
//!
//! {
//! let root = Span::root("root", SpanContext::new(TraceId(12), SpanId::default()));
Expand Down Expand Up @@ -84,10 +84,10 @@
//!
//! ```
//! use minitrace::prelude::*;
//! use minitrace::collector::TerminalReporter;
//! use minitrace::collector::ConsoleReporter;
//! use minitrace::collector::Config;
//!
//! minitrace::set_reporter(TerminalReporter, Config::default());
//! minitrace::set_reporter(ConsoleReporter, Config::default());
//!
//! {
//! let root = Span::root("root", SpanContext::new(TraceId(12), SpanId::default()));
Expand All @@ -113,7 +113,7 @@
//!
//! ```
//! use minitrace::prelude::*;
//! use minitrace::collector::TerminalReporter;
//! use minitrace::collector::ConsoleReporter;
//! use minitrace::collector::Config;
//! use futures::executor::block_on;
//!
Expand All @@ -127,7 +127,7 @@
//! futures_timer::Delay::new(std::time::Duration::from_millis(i)).await;
//! }
//!
//! minitrace::set_reporter(TerminalReporter, Config::default());
//! minitrace::set_reporter(ConsoleReporter, Config::default());
//!
//! let root = Span::root("root", SpanContext::new(TraceId(12), SpanId::default()));
//! {
Expand Down Expand Up @@ -155,10 +155,10 @@

// If no reporter implementation is selected, the facade falls back to a “noop” implementation that ignores all log messages. The overhead zero.
//! ```
//! use minitrace::collector::TerminalReporter;
//! use minitrace::collector::ConsoleReporter;
//! use minitrace::collector::Config;
//!
//! minitrace::set_reporter(TerminalReporter, Config::default());
//! minitrace::set_reporter(ConsoleReporter, Config::default());
//!
//! minitrace::flush();
//! ```
Expand Down
2 changes: 1 addition & 1 deletion test-no-report/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2023 TiKV Project Authors. Licensed under Apache-2.0.

//! Test using minitrace without "report" feature, which means the minitrace is
//! statically disabled
//! statically disabled

#[test]
fn main() {
Expand Down

0 comments on commit 1e219f1

Please sign in to comment.