@@ -76,6 +76,7 @@ mod tests {
7676
7777 struct SpanPointerTestCase {
7878 test_name : & ' static str ,
79+ existing_links : Option < serde_json:: Value > ,
7980 span_pointers : Option < Vec < SpanPointer > > ,
8081 expected_links : Option < serde_json:: Value > ,
8182 }
@@ -85,6 +86,7 @@ mod tests {
8586 let test_cases = vec ! [
8687 SpanPointerTestCase {
8788 test_name: "adds span links to span" ,
89+ existing_links: None ,
8890 span_pointers: Some ( vec![
8991 SpanPointer {
9092 hash: "hash1" . to_string( ) ,
@@ -126,21 +128,76 @@ mod tests {
126128 } ,
127129 SpanPointerTestCase {
128130 test_name: "handles empty span pointers" ,
131+ existing_links: None ,
129132 span_pointers: Some ( vec![ ] ) ,
130133 expected_links: None ,
131134 } ,
132135 SpanPointerTestCase {
133136 test_name: "handles None span pointers" ,
137+ existing_links: None ,
134138 span_pointers: None ,
135139 expected_links: None ,
136140 } ,
141+ SpanPointerTestCase {
142+ test_name: "appends to existing span links" ,
143+ existing_links: Some ( json!( [ {
144+ "attributes" : {
145+ "link.kind" : "span-pointer" ,
146+ "ptr.dir" : "d" ,
147+ "ptr.hash" : "hash1" ,
148+ "ptr.kind" : "test.kind1"
149+ } ,
150+ "span_id" : 123 ,
151+ "trace_id" : 456 ,
152+ "trace_id_high" : 0 ,
153+ "tracestate" : "" ,
154+ "flags" : 0
155+ } ] ) ) ,
156+ span_pointers: Some ( vec![ SpanPointer {
157+ hash: "hash2" . to_string( ) ,
158+ kind: "test.kind2" . to_string( ) ,
159+ } ] ) ,
160+ expected_links: Some ( json!( [
161+ {
162+ "attributes" : {
163+ "link.kind" : "span-pointer" ,
164+ "ptr.dir" : "d" ,
165+ "ptr.hash" : "hash1" ,
166+ "ptr.kind" : "test.kind1"
167+ } ,
168+ "span_id" : 123 ,
169+ "trace_id" : 456 ,
170+ "trace_id_high" : 0 ,
171+ "tracestate" : "" ,
172+ "flags" : 0
173+ } ,
174+ {
175+ "attributes" : {
176+ "link.kind" : "span-pointer" ,
177+ "ptr.dir" : "u" ,
178+ "ptr.hash" : "hash2" ,
179+ "ptr.kind" : "test.kind2"
180+ } ,
181+ "span_id" : 0 ,
182+ "trace_id" : 0 ,
183+ "trace_id_high" : 0 ,
184+ "tracestate" : "" ,
185+ "flags" : 0
186+ }
187+ ] ) ) ,
188+ } ,
137189 ] ;
138190
139191 for case in test_cases {
140192 let mut test_span = TestSpan {
141193 meta : HashMap :: new ( ) ,
142194 } ;
143195
196+ // Set up existing links if any
197+ if let Some ( links) = case. existing_links {
198+ test_span. meta . insert ( "_dd.span_links" . to_string ( ) , links. to_string ( ) ) ;
199+ }
200+
144201 attach_span_pointers_to_meta ( & mut test_span. meta , & case. span_pointers ) ;
145202
146203 match case. expected_links {
0 commit comments