@@ -25,7 +25,9 @@ use opentelemetry_proto::tonic::metrics::v1::{
2525} ;
2626use serde_json:: Value ;
2727
28- use super :: otel_utils:: { insert_attributes, insert_number_if_some} ;
28+ use super :: otel_utils:: {
29+ convert_epoch_nano_to_timestamp, insert_attributes, insert_number_if_some,
30+ } ;
2931
3032/// otel metrics event has json array for exemplar
3133/// this function flatten the exemplar json array
@@ -37,7 +39,9 @@ fn flatten_exemplar(exemplars: &[Exemplar]) -> BTreeMap<String, Value> {
3739 insert_attributes ( & mut exemplar_json, & exemplar. filtered_attributes ) ;
3840 exemplar_json. insert (
3941 "exemplar_time_unix_nano" . to_string ( ) ,
40- Value :: Number ( exemplar. time_unix_nano . into ( ) ) ,
42+ Value :: String ( convert_epoch_nano_to_timestamp (
43+ exemplar. time_unix_nano as i64 ,
44+ ) ) ,
4145 ) ;
4246 exemplar_json. insert (
4347 "exemplar_span_id" . to_string ( ) ,
@@ -79,11 +83,15 @@ fn flatten_number_data_points(data_points: &[NumberDataPoint]) -> Vec<BTreeMap<S
7983 insert_attributes ( & mut data_point_json, & data_point. attributes ) ;
8084 data_point_json. insert (
8185 "start_time_unix_nano" . to_string ( ) ,
82- Value :: Number ( data_point. start_time_unix_nano . into ( ) ) ,
86+ Value :: String ( convert_epoch_nano_to_timestamp (
87+ data_point. start_time_unix_nano as i64 ,
88+ ) ) ,
8389 ) ;
8490 data_point_json. insert (
8591 "time_unix_nano" . to_string ( ) ,
86- Value :: Number ( data_point. time_unix_nano . into ( ) ) ,
92+ Value :: String ( convert_epoch_nano_to_timestamp (
93+ data_point. time_unix_nano as i64 ,
94+ ) ) ,
8795 ) ;
8896 let exemplar_json = flatten_exemplar ( & data_point. exemplars ) ;
8997 for ( key, value) in exemplar_json {
@@ -167,11 +175,15 @@ fn flatten_histogram(histogram: &Histogram) -> Vec<BTreeMap<String, Value>> {
167175 insert_attributes ( & mut data_point_json, & data_point. attributes ) ;
168176 data_point_json. insert (
169177 "histogram_start_time_unix_nano" . to_string ( ) ,
170- Value :: Number ( data_point. start_time_unix_nano . into ( ) ) ,
178+ Value :: String ( convert_epoch_nano_to_timestamp (
179+ data_point. start_time_unix_nano as i64 ,
180+ ) ) ,
171181 ) ;
172182 data_point_json. insert (
173183 "histogram_time_unix_nano" . to_string ( ) ,
174- Value :: Number ( data_point. time_unix_nano . into ( ) ) ,
184+ Value :: String ( convert_epoch_nano_to_timestamp (
185+ data_point. time_unix_nano as i64 ,
186+ ) ) ,
175187 ) ;
176188 data_point_json. insert (
177189 "histogram_data_point_count" . to_string ( ) ,
@@ -242,11 +254,15 @@ fn flatten_exp_histogram(exp_histogram: &ExponentialHistogram) -> Vec<BTreeMap<S
242254 insert_attributes ( & mut data_point_json, & data_point. attributes ) ;
243255 data_point_json. insert (
244256 "exponential_histogram_start_time_unix_nano" . to_string ( ) ,
245- Value :: Number ( data_point. start_time_unix_nano . into ( ) ) ,
257+ Value :: String ( convert_epoch_nano_to_timestamp (
258+ data_point. start_time_unix_nano as i64 ,
259+ ) ) ,
246260 ) ;
247261 data_point_json. insert (
248262 "exponential_histogram_time_unix_nano" . to_string ( ) ,
249- Value :: Number ( data_point. time_unix_nano . into ( ) ) ,
263+ Value :: String ( convert_epoch_nano_to_timestamp (
264+ data_point. time_unix_nano as i64 ,
265+ ) ) ,
250266 ) ;
251267 data_point_json. insert (
252268 "exponential_histogram_data_point_count" . to_string ( ) ,
@@ -306,11 +322,15 @@ fn flatten_summary(summary: &Summary) -> Vec<BTreeMap<String, Value>> {
306322 insert_attributes ( & mut data_point_json, & data_point. attributes ) ;
307323 data_point_json. insert (
308324 "summary_start_time_unix_nano" . to_string ( ) ,
309- Value :: Number ( data_point. start_time_unix_nano . into ( ) ) ,
325+ Value :: String ( convert_epoch_nano_to_timestamp (
326+ data_point. start_time_unix_nano as i64 ,
327+ ) ) ,
310328 ) ;
311329 data_point_json. insert (
312330 "summary_time_unix_nano" . to_string ( ) ,
313- Value :: Number ( data_point. time_unix_nano . into ( ) ) ,
331+ Value :: String ( convert_epoch_nano_to_timestamp (
332+ data_point. time_unix_nano as i64 ,
333+ ) ) ,
314334 ) ;
315335 data_point_json. insert (
316336 "summary_data_point_count" . to_string ( ) ,
0 commit comments