Skip to content

Commit f668a0b

Browse files
WaelBKZJason Zhou
authored andcommitted
fix: handle missing span_name in logging test assertions (#2665)
Signed-off-by: Jason Zhou <jasonzho@jasonzho-mlt.client.nvidia.com>
1 parent b25fbad commit f668a0b

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

lib/runtime/src/logging.rs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,28 +1009,40 @@ pub mod tests {
10091009

10101010
// Parent span has no parent_id
10111011
for log_line in &lines {
1012-
if log_line.get("span_name").unwrap().as_str().unwrap() == "parent" {
1013-
assert!(log_line.get("parent_id").is_none());
1012+
if let Some(span_name) = log_line.get("span_name") {
1013+
if let Some(span_name_str) = span_name.as_str() {
1014+
if span_name_str == "parent" {
1015+
assert!(log_line.get("parent_id").is_none());
1016+
}
1017+
}
10141018
}
10151019
}
10161020

10171021
// Child span's parent_id is parent_span_id
10181022
for log_line in &lines {
1019-
if log_line.get("span_name").unwrap().as_str().unwrap() == "child" {
1020-
assert_eq!(
1021-
log_line.get("parent_id").unwrap().as_str().unwrap(),
1022-
&parent_span_id
1023-
);
1023+
if let Some(span_name) = log_line.get("span_name") {
1024+
if let Some(span_name_str) = span_name.as_str() {
1025+
if span_name_str == "child" {
1026+
assert_eq!(
1027+
log_line.get("parent_id").unwrap().as_str().unwrap(),
1028+
&parent_span_id
1029+
);
1030+
}
1031+
}
10241032
}
10251033
}
10261034

10271035
// Grandchild span's parent_id is child_span_id
10281036
for log_line in &lines {
1029-
if log_line.get("span_name").unwrap().as_str().unwrap() == "grandchild" {
1030-
assert_eq!(
1031-
log_line.get("parent_id").unwrap().as_str().unwrap(),
1032-
&child_span_id
1033-
);
1037+
if let Some(span_name) = log_line.get("span_name") {
1038+
if let Some(span_name_str) = span_name.as_str() {
1039+
if span_name_str == "grandchild" {
1040+
assert_eq!(
1041+
log_line.get("parent_id").unwrap().as_str().unwrap(),
1042+
&child_span_id
1043+
);
1044+
}
1045+
}
10341046
}
10351047
}
10361048

0 commit comments

Comments
 (0)