@@ -25,7 +25,9 @@ use opentelemetry_proto::tonic::metrics::v1::{
25
25
} ;
26
26
use serde_json:: Value ;
27
27
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
+ } ;
29
31
30
32
/// otel metrics event has json array for exemplar
31
33
/// this function flatten the exemplar json array
@@ -37,7 +39,9 @@ fn flatten_exemplar(exemplars: &[Exemplar]) -> BTreeMap<String, Value> {
37
39
insert_attributes ( & mut exemplar_json, & exemplar. filtered_attributes ) ;
38
40
exemplar_json. insert (
39
41
"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
+ ) ) ,
41
45
) ;
42
46
exemplar_json. insert (
43
47
"exemplar_span_id" . to_string ( ) ,
@@ -79,11 +83,15 @@ fn flatten_number_data_points(data_points: &[NumberDataPoint]) -> Vec<BTreeMap<S
79
83
insert_attributes ( & mut data_point_json, & data_point. attributes ) ;
80
84
data_point_json. insert (
81
85
"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
+ ) ) ,
83
89
) ;
84
90
data_point_json. insert (
85
91
"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
+ ) ) ,
87
95
) ;
88
96
let exemplar_json = flatten_exemplar ( & data_point. exemplars ) ;
89
97
for ( key, value) in exemplar_json {
@@ -167,11 +175,15 @@ fn flatten_histogram(histogram: &Histogram) -> Vec<BTreeMap<String, Value>> {
167
175
insert_attributes ( & mut data_point_json, & data_point. attributes ) ;
168
176
data_point_json. insert (
169
177
"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
+ ) ) ,
171
181
) ;
172
182
data_point_json. insert (
173
183
"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
+ ) ) ,
175
187
) ;
176
188
data_point_json. insert (
177
189
"histogram_data_point_count" . to_string ( ) ,
@@ -242,11 +254,15 @@ fn flatten_exp_histogram(exp_histogram: &ExponentialHistogram) -> Vec<BTreeMap<S
242
254
insert_attributes ( & mut data_point_json, & data_point. attributes ) ;
243
255
data_point_json. insert (
244
256
"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
+ ) ) ,
246
260
) ;
247
261
data_point_json. insert (
248
262
"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
+ ) ) ,
250
266
) ;
251
267
data_point_json. insert (
252
268
"exponential_histogram_data_point_count" . to_string ( ) ,
@@ -306,11 +322,15 @@ fn flatten_summary(summary: &Summary) -> Vec<BTreeMap<String, Value>> {
306
322
insert_attributes ( & mut data_point_json, & data_point. attributes ) ;
307
323
data_point_json. insert (
308
324
"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
+ ) ) ,
310
328
) ;
311
329
data_point_json. insert (
312
330
"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
+ ) ) ,
314
334
) ;
315
335
data_point_json. insert (
316
336
"summary_data_point_count" . to_string ( ) ,
0 commit comments