Skip to content

Commit 83c96fe

Browse files
committed
add test test_get_traces_from_request_body_with_span_links
1 parent 32ed77c commit 83c96fe

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

trace-utils/src/trace_utils.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,66 @@ mod tests {
902902
}
903903
}
904904

905+
#[tokio::test]
906+
async fn test_get_traces_from_request_body_with_span_links() {
907+
let trace_input = json!([[{
908+
"service": "test-service",
909+
"name": "test-name",
910+
"resource": "test-resource",
911+
"trace_id": 111,
912+
"span_id": 222,
913+
"parent_id": 333,
914+
"start": 1,
915+
"duration": 5,
916+
"error": 0,
917+
"meta": {},
918+
"metrics": {},
919+
"span_links": [{
920+
"trace_id": 999,
921+
"span_id": 888,
922+
"trace_id_high": 777,
923+
"attributes": {"key": "value"},
924+
"tracestate": "vendor=value"
925+
// flags field intentionally omitted
926+
}]
927+
}]]);
928+
929+
let expected_output = vec![vec![pb::Span {
930+
service: "test-service".to_string(),
931+
name: "test-name".to_string(),
932+
resource: "test-resource".to_string(),
933+
trace_id: 111,
934+
span_id: 222,
935+
parent_id: 333,
936+
start: 1,
937+
duration: 5,
938+
error: 0,
939+
meta: HashMap::new(),
940+
metrics: HashMap::new(),
941+
meta_struct: HashMap::new(),
942+
r#type: String::new(),
943+
span_links: vec![pb::SpanLink {
944+
trace_id: 999,
945+
span_id: 888,
946+
trace_id_high: 777,
947+
attributes: HashMap::from([
948+
("key".to_string(), "value".to_string())
949+
]),
950+
tracestate: "vendor=value".to_string(),
951+
flags: 0, // Should default to 0 when omitted
952+
}],
953+
}]];
954+
955+
let bytes = rmp_serde::to_vec(&trace_input).unwrap();
956+
let request = Request::builder()
957+
.body(hyper::body::Body::from(bytes))
958+
.unwrap();
959+
960+
let res = get_traces_from_request_body(request.into_body()).await;
961+
assert!(res.is_ok(), "Failed to deserialize: {:?}", res);
962+
assert_eq!(res.unwrap().1, expected_output);
963+
}
964+
905965
#[test]
906966
fn test_get_root_span_index_from_complete_trace() {
907967
let trace = vec![

0 commit comments

Comments
 (0)