test: use Metrics_callbacks from emit1

This commit is contained in:
Simon Cruanes 2022-04-29 16:50:52 -04:00
parent 6744123075
commit 5b3f49890b
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4

View file

@ -5,11 +5,15 @@ let (let@) f x = f x
let sleep_inner = ref 0.1
let sleep_outer = ref 2.0
let num_sleep = ref 0
let run () =
Printf.printf "collector is on %S\n%!" (Opentelemetry_client_ocurl.get_url());
T.GC_metrics.basic_setup();
T.Metrics_callbacks.register (fun () ->
T.Metrics.[ sum ~name:"num-sleep" ~is_monotonic:true [int !num_sleep] ]);
let i = ref 0 in
while true do
let@ scope =
@ -22,7 +26,9 @@ let run () =
let@ scope = T.Trace.with_ ~kind:T.Span.Span_kind_internal ~scope
~attrs:["j", `Int j]
"loop.inner" in
Unix.sleepf !sleep_outer;
incr num_sleep;
incr i;
@ -33,7 +39,10 @@ let run () =
(* allocate some stuff *)
let _arr = Sys.opaque_identity @@ Array.make (25 * 25551) 42.0 in
ignore _arr;
Unix.sleepf !sleep_inner;
incr num_sleep;
if j=4 && !i mod 13 = 0 then failwith "oh no"; (* simulate a failure *)
T.Trace.add_event scope (fun()->T.Event.make "done with alloc");