@@ -24,7 +24,7 @@ use opentelemetry_proto::tonic::metrics::v1::{
2424use serde_json:: { Map , Value } ;
2525
2626use super :: otel_utils:: {
27- convert_epoch_nano_to_timestamp , fetch_attributes_string , insert_attributes,
27+ add_other_attributes_if_not_empty , convert_epoch_nano_to_timestamp , insert_attributes,
2828 insert_number_if_some, merge_attributes_in_json,
2929} ;
3030
@@ -83,13 +83,7 @@ fn flatten_exemplar(exemplars: &[Exemplar]) -> Vec<Map<String, Value>> {
8383 }
8484 }
8585 }
86- if !other_attributes. is_empty ( ) {
87- let other_attributes = fetch_attributes_string ( & other_attributes) ;
88- exemplar_json. insert (
89- "other_attributes" . to_string ( ) ,
90- Value :: String ( other_attributes) ,
91- ) ;
92- }
86+ add_other_attributes_if_not_empty ( & mut exemplar_json, & other_attributes) ;
9387 exemplar_json
9488 } )
9589 . collect ( )
@@ -131,11 +125,8 @@ fn flatten_number_data_points(data_points: &[NumberDataPoint]) -> Vec<Map<String
131125 data_point_json. insert ( key, value) ;
132126 }
133127 }
134- } else if !other_attributes. is_empty ( ) {
135- data_point_json. insert (
136- "other_attributes" . to_string ( ) ,
137- Value :: String ( fetch_attributes_string ( & other_attributes) ) ,
138- ) ;
128+ } else {
129+ add_other_attributes_if_not_empty ( & mut data_point_json, & other_attributes) ;
139130 }
140131
141132 data_point_json. extend ( flatten_data_point_flags ( data_point. flags ) ) ;
@@ -270,11 +261,8 @@ fn flatten_histogram(histogram: &Histogram) -> Vec<Map<String, Value>> {
270261 data_point_json. insert ( key, value) ;
271262 }
272263 }
273- } else if !other_attributes. is_empty ( ) {
274- data_point_json. insert (
275- "other_attributes" . to_string ( ) ,
276- Value :: String ( fetch_attributes_string ( & other_attributes) ) ,
277- ) ;
264+ } else {
265+ add_other_attributes_if_not_empty ( & mut data_point_json, & other_attributes) ;
278266 }
279267
280268 data_point_json. extend ( flatten_data_point_flags ( data_point. flags ) ) ;
@@ -372,11 +360,8 @@ fn flatten_exp_histogram(exp_histogram: &ExponentialHistogram) -> Vec<Map<String
372360 data_point_json. insert ( key, value) ;
373361 }
374362 }
375- } else if !other_attributes. is_empty ( ) {
376- data_point_json. insert (
377- "other_attributes" . to_string ( ) ,
378- Value :: String ( fetch_attributes_string ( & other_attributes) ) ,
379- ) ;
363+ } else {
364+ add_other_attributes_if_not_empty ( & mut data_point_json, & other_attributes) ;
380365 }
381366
382367 data_points_json. push ( data_point_json) ;
@@ -460,12 +445,7 @@ fn flatten_summary(summary: &Summary) -> Vec<Map<String, Value>> {
460445 ) ,
461446 ) ;
462447
463- if !other_attributes. is_empty ( ) {
464- data_point_json. insert (
465- "other_attributes" . to_string ( ) ,
466- Value :: String ( fetch_attributes_string ( & other_attributes) ) ,
467- ) ;
468- }
448+ add_other_attributes_if_not_empty ( & mut data_point_json, & other_attributes) ;
469449
470450 data_points_json. push ( data_point_json) ;
471451 }
0 commit comments