Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to track upstream changes #3

Merged
merged 7 commits into from
Feb 8, 2019
Prev Previous commit
Add parent span names to TraceLogger
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
  • Loading branch information
hawkw committed Feb 7, 2019
commit 349b22c50038059c8b2e2fda5a7de498fc30ea9d
42 changes: 37 additions & 5 deletions tokio-trace-log/src/lib.rs
Original file line number Diff line number Diff line change
@@ -153,13 +153,13 @@ pub struct TraceLogger {
current: tokio_trace_subscriber::CurrentSpanPerThread,
}

#[derive(Default)]
pub struct TraceLoggerBuilder {
log_span_closes: bool,
log_enters: bool,
log_exits: bool,
log_ids: bool,
parent_fields: bool,
log_parent: bool,
}

// ===== impl LogTracer =====
@@ -241,11 +241,29 @@ impl TraceLoggerBuilder {
Self { log_ids, ..self }
}

pub fn with_parent_names(self, log_parent: bool) -> Self {
Self { log_parent, ..self }
}


pub fn finish(self) -> TraceLogger {
TraceLogger::from_builder(self)
}
}

impl Default for TraceLoggerBuilder {
fn default() -> Self {
TraceLoggerBuilder {
log_span_closes: false,
parent_fields: true,
log_exits: false,
log_ids: false,
log_parent: true,
log_enters: false,
}
}
}

struct SpanLineBuilder {
parent: Option<Id>,
ref_count: usize,
@@ -423,20 +441,34 @@ impl Subscriber for TraceLogger {
let logger = log::logger();
if logger.enabled(&log_meta) {
let spans = self.spans.lock().unwrap();
let current_fields = self.current.id()
let current = self.current.id()
.and_then(|id| {
spans.get(&id)
});
let (current_fields, parent) = current
.map(|span| {
let fields = span.fields.as_ref();
let parent = if self.settings.log_parent {
Some(span.name)
} else {
None
};
(fields, parent)
})
.map(|span| span.fields.as_ref())
.unwrap_or("");
.unwrap_or(("", None));
logger.log(
&log::Record::builder()
.metadata(log_meta)
.target(meta.target)
.module_path(meta.module_path.as_ref().map(|&p| p))
.file(meta.file.as_ref().map(|&f| f))
.line(meta.line)
.args(format_args!("{}{}", LogEvent(event), current_fields))
.args(format_args!("{}{}{}{}",
parent.unwrap_or(""),
if parent.is_some() { ": " } else { "" },
LogEvent(event),
current_fields,
))
.build(),
);