@@ -9,7 +9,7 @@ use uuid::Uuid;
99
1010use sentry_arroyo:: backends:: kafka:: types:: KafkaPayload ;
1111use sentry_protos:: snuba:: v1:: any_value:: Value ;
12- use sentry_protos:: snuba:: v1:: TraceItem ;
12+ use sentry_protos:: snuba:: v1:: { ArrayValue , TraceItem } ;
1313
1414use crate :: config:: ProcessorConfig ;
1515use crate :: processors:: utils:: enforce_retention;
@@ -88,8 +88,8 @@ impl TryFrom<TraceItem> for EAPItem {
8888 Some ( Value :: DoubleValue ( double) ) => eap_item. attributes . insert_float ( key, double) ,
8989 Some ( Value :: IntValue ( int) ) => eap_item. attributes . insert_int ( key, int) ,
9090 Some ( Value :: BoolValue ( bool) ) => eap_item. attributes . insert_bool ( key, bool) ,
91+ Some ( Value :: ArrayValue ( array) ) => eap_item. attributes . insert_array ( key, array) ,
9192 Some ( Value :: BytesValue ( _) ) => ( ) ,
92- Some ( Value :: ArrayValue ( _) ) => ( ) ,
9393 Some ( Value :: KvlistValue ( _) ) => ( ) ,
9494 None => ( ) ,
9595 }
@@ -137,9 +137,17 @@ macro_rules! seq_attrs {
137137 }
138138}
139139
140+ #[ derive( Debug , Serialize , PartialEq ) ]
141+ enum EAPValue {
142+ StringValue ( String ) ,
143+ BoolValue ( bool ) ,
144+ IntValue ( i64 ) ,
145+ DoubleValue ( f64 ) ,
146+ }
147+
140148seq_attrs ! {
141149#[ derive( Debug , Default , Serialize ) ]
142- pub ( crate ) struct AttributeMap {
150+ struct AttributeMap {
143151 attributes_bool: HashMap <String , bool >,
144152 attributes_int: HashMap <String , i64 >,
145153 #(
@@ -149,6 +157,8 @@ pub(crate) struct AttributeMap {
149157 #[ serde( skip_serializing_if = "HashMap::is_empty" ) ]
150158 attributes_float_~N : HashMap <String , f64 >,
151159 ) *
160+
161+ attributes_array: HashMap <String , Vec <EAPValue >>,
152162}
153163}
154164
@@ -188,14 +198,33 @@ impl AttributeMap {
188198 self . insert_float ( k. clone ( ) , v as f64 ) ;
189199 self . attributes_int . insert ( k, v) ;
190200 }
201+
202+ pub fn insert_array ( & mut self , k : String , v : ArrayValue ) {
203+ let mut values: Vec < EAPValue > = Vec :: default ( ) ;
204+ for value in v. values {
205+ match value. value {
206+ Some ( Value :: StringValue ( string) ) => values. push ( EAPValue :: StringValue ( string) ) ,
207+ Some ( Value :: DoubleValue ( double) ) => values. push ( EAPValue :: DoubleValue ( double) ) ,
208+ Some ( Value :: IntValue ( int) ) => values. push ( EAPValue :: IntValue ( int) ) ,
209+ Some ( Value :: BoolValue ( bool) ) => values. push ( EAPValue :: BoolValue ( bool) ) ,
210+ Some ( Value :: BytesValue ( _) ) => ( ) ,
211+ Some ( Value :: KvlistValue ( _) ) => ( ) ,
212+ Some ( Value :: ArrayValue ( _) ) => ( ) ,
213+ None => ( ) ,
214+ }
215+ }
216+
217+ self . attributes_array . insert ( k, values) ;
218+ }
191219}
192220
193221#[ cfg( test) ]
194222mod tests {
195223 use std:: time:: SystemTime ;
196224
197225 use prost_types:: Timestamp ;
198- use sentry_protos:: snuba:: v1:: TraceItemType ;
226+ use sentry_protos:: snuba:: v1:: any_value:: Value ;
227+ use sentry_protos:: snuba:: v1:: { AnyValue , ArrayValue , TraceItemType } ;
199228 use serde:: Deserialize ;
200229
201230 use super :: * ;
@@ -295,4 +324,34 @@ mod tests {
295324
296325 assert_eq ! ( item. downsampled_retention_days, 365 ) ;
297326 }
327+
328+ #[ test]
329+ fn test_insert_arrays ( ) {
330+ let item_id = Uuid :: new_v4 ( ) ;
331+ let mut trace_item = generate_trace_item ( item_id) ;
332+
333+ trace_item. attributes . insert (
334+ "arrays" . to_string ( ) ,
335+ AnyValue {
336+ value : Some ( Value :: ArrayValue ( ArrayValue {
337+ values : vec ! [ AnyValue {
338+ value: Some ( Value :: IntValue ( 1234567890 ) ) ,
339+ } ] ,
340+ } ) ) ,
341+ } ,
342+ ) ;
343+
344+ let eap_item = EAPItem :: try_from ( trace_item) ;
345+
346+ assert ! ( eap_item. is_ok( ) ) ;
347+ assert_eq ! (
348+ eap_item
349+ . unwrap( )
350+ . attributes
351+ . attributes_array
352+ . get( "arrays" )
353+ . unwrap( ) [ 0 ] ,
354+ EAPValue :: IntValue ( 1234567890 )
355+ ) ;
356+ }
298357}
0 commit comments