@@ -112,7 +112,7 @@ fake_info_metric(Name, Scope, Attributes, Description) ->
112
112
description = Description ,
113
113
data = # gauge {datapoints = [# datapoint {
114
114
attributes = Attributes , value = 1 , exemplars = [],
115
- flags = 0 , start_time_unix_nano = 0 , time_unix_nano = 0
115
+ flags = 0 , start_time = 0 , time = 0
116
116
}]}
117
117
}.
118
118
@@ -191,7 +191,7 @@ data(MetricName, Datapoints, Scope, AddCreated, #opts{add_scope_info=AddScopeInf
191
191
192
192
lists :foldl (
193
193
fun (DP , Acc ) ->
194
- datapoint (DP , MetricName , AddCreated , ScopeLabels , Acc )
194
+ datapoint (DP , MetricName , AddCreated , ScopeLabels , Acc )
195
195
end ,
196
196
[[], []],
197
197
Datapoints
@@ -200,12 +200,12 @@ data(MetricName, Datapoints, Scope, AddCreated, #opts{add_scope_info=AddScopeInf
200
200
datapoint (# datapoint {} = DP , MetricName , AddCreated , ScopeLabels , [Points , Created ]) ->
201
201
Labels = surround_labels (join_labels (ScopeLabels , labels (DP # datapoint .attributes ))),
202
202
Point = [MetricName , Labels , " " , number_to_binary (DP # datapoint .value ), " \n " ],
203
- Created1 = created (AddCreated , Created , MetricName , Labels , DP # datapoint .start_time_unix_nano ),
203
+ Created1 = created (AddCreated , Created , MetricName , Labels , DP # datapoint .start_time ),
204
204
[[Point | Points ], Created1 ];
205
205
datapoint (# histogram_datapoint {} = DP , MetricName , AddCreated , ScopeLabels , [Points , Created ]) ->
206
206
Labels = join_labels (ScopeLabels , labels (DP # histogram_datapoint .attributes )),
207
207
SurroundedLabels = surround_labels (Labels ),
208
-
208
+
209
209
Count = lists :sum (DP # histogram_datapoint .bucket_counts ),
210
210
CountPoint = [MetricName , " _count" , SurroundedLabels , " " , number_to_binary (Count ), " \n " ],
211
211
@@ -223,14 +223,14 @@ datapoint(#histogram_datapoint{} = DP, MetricName, AddCreated, ScopeLabels, [Poi
223
223
lists :zip (DP # histogram_datapoint .bucket_counts , DP # histogram_datapoint .explicit_bounds ++ [<<" +Inf" >>])
224
224
),
225
225
226
- Created1 = created (AddCreated , Created , MetricName , SurroundedLabels , DP # histogram_datapoint .start_time_unix_nano ),
226
+ Created1 = created (AddCreated , Created , MetricName , SurroundedLabels , DP # histogram_datapoint .start_time ),
227
227
228
228
[[Buckets , CountPoint , SumPoint | Points ], Created1 ].
229
229
230
- created (false , Created , _MetricName , _Labels , _Value ) ->
230
+ created (false , Created , _MetricName , _Labels , _StartTime ) ->
231
231
Created ;
232
- created (true , Created , MetricName , Labels , Value ) ->
233
- [[MetricName , " _created" , Labels , " " , number_to_binary (Value ), " \n " ] | Created ].
232
+ created (true , Created , MetricName , Labels , StartTime ) ->
233
+ [[MetricName , " _created" , Labels , " " , number_to_binary (opentelemetry : timestamp_to_nano ( StartTime ) ), " \n " ] | Created ].
234
234
235
235
join_labels (<<>>, L ) -> L ;
236
236
join_labels (L , <<>> )-> L ;
@@ -328,12 +328,16 @@ escape_help_char(X) ->
328
328
329
329
- ifdef (TEST ).
330
330
331
+ nano_to_timestamp (Nano ) ->
332
+ Offset = erlang :time_offset (),
333
+ erlang :convert_time_unit (Nano , nanosecond , native ) - Offset .
334
+
331
335
metrics_to_string (Metrics ) ->
332
336
metrics_to_string (Metrics , #{}).
333
337
334
338
metrics_to_string (Metrics , Opts ) ->
335
339
Resource = otel_resource :create (#{" res" => " b" }, " url" ),
336
- {ok , Opts1 } = init (Opts ),
340
+ {ok , Opts1 } = init (Opts #{ order => ordered } ),
337
341
lists :flatten (io_lib :format (" ~ts " , [parse_metrics (Metrics , Resource , Opts1 )])).
338
342
339
343
lines_join (Lines ) ->
@@ -376,15 +380,15 @@ monotonic_counter_test() ->
376
380
datapoints = [
377
381
# datapoint {
378
382
attributes = #{},
379
- start_time_unix_nano = 0 ,
380
- time_unix_nano = 1 ,
383
+ start_time = nano_to_timestamp ( 0 ) ,
384
+ time = nano_to_timestamp ( 1 ) ,
381
385
value = 2 ,
382
386
flags = 0
383
387
},
384
388
# datapoint {
385
389
attributes = #{<<" foo" >> => 1 },
386
- start_time_unix_nano = 123 ,
387
- time_unix_nano = 456 ,
390
+ start_time = nano_to_timestamp ( 123 ) ,
391
+ time = nano_to_timestamp ( 456 ) ,
388
392
value = 789 ,
389
393
flags = 0
390
394
}
@@ -427,8 +431,8 @@ not_monotonic_counter_test() ->
427
431
datapoints = [
428
432
# datapoint {
429
433
attributes = #{},
430
- start_time_unix_nano = 0 ,
431
- time_unix_nano = 1 ,
434
+ start_time = nano_to_timestamp ( 0 ) ,
435
+ time = nano_to_timestamp ( 1 ) ,
432
436
value = 2 ,
433
437
flags = 0
434
438
}
@@ -465,8 +469,8 @@ gauge_test() ->
465
469
datapoints = [
466
470
# datapoint {
467
471
attributes = #{<<" foo" >> => 1 },
468
- start_time_unix_nano = 123 ,
469
- time_unix_nano = 456 ,
472
+ start_time = nano_to_timestamp ( 123 ) ,
473
+ time = nano_to_timestamp ( 456 ) ,
470
474
value = 2.0 ,
471
475
flags = 0
472
476
}
@@ -506,8 +510,8 @@ monotonic_histogram_test() ->
506
510
datapoints = [
507
511
# histogram_datapoint {
508
512
attributes = #{},
509
- start_time_unix_nano = 0 ,
510
- time_unix_nano = 1 ,
513
+ start_time = nano_to_timestamp ( 0 ) ,
514
+ time = nano_to_timestamp ( 1 ) ,
511
515
count = 3 ,
512
516
sum = 7 ,
513
517
bucket_counts = [2 ,0 ,1 ],
@@ -557,8 +561,8 @@ not_monotonic_histogram_test() ->
557
561
datapoints = [
558
562
# histogram_datapoint {
559
563
attributes = #{},
560
- start_time_unix_nano = 0 ,
561
- time_unix_nano = 1 ,
564
+ start_time = nano_to_timestamp ( 0 ) ,
565
+ time = nano_to_timestamp ( 1 ) ,
562
566
count = 1 ,
563
567
sum = 3 ,
564
568
bucket_counts = [0 ,0 ,1 ],
@@ -608,8 +612,8 @@ no_otel_scope_test() ->
608
612
datapoints = [
609
613
# datapoint {
610
614
attributes = #{},
611
- start_time_unix_nano = 0 ,
612
- time_unix_nano = 1 ,
615
+ start_time = nano_to_timestamp ( 0 ) ,
616
+ time = nano_to_timestamp ( 1 ) ,
613
617
value = 2 ,
614
618
flags = 0
615
619
}
0 commit comments