From 463152e193c07c8752288a06ae9e805e19e99f99 Mon Sep 17 00:00:00 2001 From: Dominik Boehi Date: Tue, 30 Jan 2024 17:46:05 +0100 Subject: [PATCH 1/2] Properly detect sequences --- src/state.rs | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/state.rs b/src/state.rs index 46b73f1..f658d50 100644 --- a/src/state.rs +++ b/src/state.rs @@ -9,6 +9,19 @@ pub struct ParseError { _error: serde_json::Error, } +fn get_previous_span(event: &Event) -> Option<&Span> { + if let Some(spans) = &event.spans { + if spans.len() > 1 { + let last_span = spans.get(spans.len() - 1).unwrap(); + Some(&last_span) + } else { + None + } + } else { + None + } +} + #[derive(Debug, Clone, PartialEq, Properties)] pub struct State { pub events: Vec, @@ -49,14 +62,15 @@ impl State { let current_node = *current_node; - // The log viewer does not support actual parallel traces yet, so - // we limit ourselves to the probe-rs crate for now. - if !event.target.starts_with("probe_rs") { - continue; - } - match &event.fields.message[..] { "enter" => { + let previous_span = get_previous_span(&event); + + if &previous_span != current_span { + log::debug!("Ignoring event: {:?}, previous span {:?} does not match active span {:?}", event.fields.message, previous_span, current_span); + continue; + } + let node = Node { index: Some(index), children: vec![], @@ -71,7 +85,11 @@ impl State { .children .push(EventType::Node(node_index)); - log::debug!("Entering span {:?}", event.span.as_ref()); + log::debug!( + "Entering span {:?}, current_spans: {:?}", + event.span.as_ref(), + event.spans + ); tree.push((node_index, event.span.as_ref())); } @@ -84,6 +102,7 @@ impl State { current_span ); } else { + log::debug!("Exiting span {:?}", event.span.as_ref()); let _ = tree.pop(); } } From 65829035ab8f8c4aae3b383014f9042231d6c7ae Mon Sep 17 00:00:00 2001 From: Dominik Boehi Date: Tue, 30 Jan 2024 18:12:40 +0100 Subject: [PATCH 2/2] Fix clippy warning --- src/state.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/state.rs b/src/state.rs index f658d50..6f2ef3e 100644 --- a/src/state.rs +++ b/src/state.rs @@ -12,8 +12,7 @@ pub struct ParseError { fn get_previous_span(event: &Event) -> Option<&Span> { if let Some(spans) = &event.spans { if spans.len() > 1 { - let last_span = spans.get(spans.len() - 1).unwrap(); - Some(&last_span) + spans.get(spans.len() - 2) } else { None } @@ -64,10 +63,10 @@ impl State { match &event.fields.message[..] { "enter" => { - let previous_span = get_previous_span(&event); + let previous_span = get_previous_span(event); if &previous_span != current_span { - log::debug!("Ignoring event: {:?}, previous span {:?} does not match active span {:?}", event.fields.message, previous_span, current_span); + log::debug!("Ignoring event: {:?}, previous span {:?} does not match active span {:?}", event, previous_span, current_span); continue; }