Skip to content

Commit

Permalink
Add test for has_top_level
Browse files Browse the repository at this point in the history
  • Loading branch information
VianneyRuhlmann committed Aug 6, 2024
1 parent bb8ea40 commit ad4d617
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion trace-utils/src/trace_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ pub fn compute_top_level_span(trace: &mut [pb::Span]) {
}
}

/// Return true if the span has a top level key set
pub fn has_top_level(span: &pb::Span) -> bool {
span.metrics
.get(TRACER_TOP_LEVEL_KEY)
Expand Down Expand Up @@ -649,7 +650,7 @@ mod tests {
use std::collections::HashMap;

use super::{get_root_span_index, set_serverless_root_span_tags};
use crate::trace_utils::{TracerHeaderTags, MAX_PAYLOAD_SIZE};
use crate::trace_utils::{has_top_level, TracerHeaderTags, MAX_PAYLOAD_SIZE};
use crate::tracer_payload::TracerPayloadCollection;
use crate::{
test_utils::create_test_span,
Expand Down Expand Up @@ -949,4 +950,12 @@ mod tests {
);
assert_eq!(span.r#type, "serverless".to_string())
}

#[test]
fn test_has_top_level() {
let top_level_span = create_test_span(123, 1234, 12, 1, true);
let not_top_level_span = create_test_span(123, 1234, 12, 1, false);
assert!(has_top_level(&top_level_span));
assert!(!has_top_level(&not_top_level_span));
}
}

0 comments on commit ad4d617

Please sign in to comment.