@@ -76,6 +76,7 @@ mod tests {
76
76
77
77
struct SpanPointerTestCase {
78
78
test_name : & ' static str ,
79
+ existing_links : Option < serde_json:: Value > ,
79
80
span_pointers : Option < Vec < SpanPointer > > ,
80
81
expected_links : Option < serde_json:: Value > ,
81
82
}
@@ -85,6 +86,7 @@ mod tests {
85
86
let test_cases = vec ! [
86
87
SpanPointerTestCase {
87
88
test_name: "adds span links to span" ,
89
+ existing_links: None ,
88
90
span_pointers: Some ( vec![
89
91
SpanPointer {
90
92
hash: "hash1" . to_string( ) ,
@@ -126,21 +128,78 @@ mod tests {
126
128
} ,
127
129
SpanPointerTestCase {
128
130
test_name: "handles empty span pointers" ,
131
+ existing_links: None ,
129
132
span_pointers: Some ( vec![ ] ) ,
130
133
expected_links: None ,
131
134
} ,
132
135
SpanPointerTestCase {
133
136
test_name: "handles None span pointers" ,
137
+ existing_links: None ,
134
138
span_pointers: None ,
135
139
expected_links: None ,
136
140
} ,
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
+ } ,
137
189
] ;
138
190
139
191
for case in test_cases {
140
192
let mut test_span = TestSpan {
141
193
meta : HashMap :: new ( ) ,
142
194
} ;
143
195
196
+ // Set up existing links if any
197
+ if let Some ( links) = case. existing_links {
198
+ test_span
199
+ . meta
200
+ . insert ( "_dd.span_links" . to_string ( ) , links. to_string ( ) ) ;
201
+ }
202
+
144
203
attach_span_pointers_to_meta ( & mut test_span. meta , & case. span_pointers ) ;
145
204
146
205
match case. expected_links {
0 commit comments