diff --git a/trace-utils/src/trace_utils.rs b/trace-utils/src/trace_utils.rs index f4ff2011d..0369e55a3 100644 --- a/trace-utils/src/trace_utils.rs +++ b/trace-utils/src/trace_utils.rs @@ -902,6 +902,66 @@ mod tests { } } + #[tokio::test] + async fn test_get_traces_from_request_body_with_span_links() { + let trace_input = json!([[{ + "service": "test-service", + "name": "test-name", + "resource": "test-resource", + "trace_id": 111, + "span_id": 222, + "parent_id": 333, + "start": 1, + "duration": 5, + "error": 0, + "meta": {}, + "metrics": {}, + "span_links": [{ + "trace_id": 999, + "span_id": 888, + "trace_id_high": 777, + "attributes": {"key": "value"}, + "tracestate": "vendor=value" + // flags field intentionally omitted + }] + }]]); + + let expected_output = vec![vec![pb::Span { + service: "test-service".to_string(), + name: "test-name".to_string(), + resource: "test-resource".to_string(), + trace_id: 111, + span_id: 222, + parent_id: 333, + start: 1, + duration: 5, + error: 0, + meta: HashMap::new(), + metrics: HashMap::new(), + meta_struct: HashMap::new(), + r#type: String::new(), + span_links: vec![pb::SpanLink { + trace_id: 999, + span_id: 888, + trace_id_high: 777, + attributes: HashMap::from([ + ("key".to_string(), "value".to_string()) + ]), + tracestate: "vendor=value".to_string(), + flags: 0, // Should default to 0 when omitted + }], + }]]; + + let bytes = rmp_serde::to_vec(&trace_input).unwrap(); + let request = Request::builder() + .body(hyper::body::Body::from(bytes)) + .unwrap(); + + let res = get_traces_from_request_body(request.into_body()).await; + assert!(res.is_ok(), "Failed to deserialize: {:?}", res); + assert_eq!(res.unwrap().1, expected_output); + } + #[test] fn test_get_root_span_index_from_complete_trace() { let trace = vec![