mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-07 18:37:56 -05:00
wip: fix tests
This commit is contained in:
parent
c24dbebbf3
commit
2e3120fc49
3 changed files with 44 additions and 36 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
module T = Opentelemetry
|
module OT = Opentelemetry
|
||||||
module Otel_lwt = Opentelemetry_lwt
|
module Otel_lwt = Opentelemetry_lwt
|
||||||
|
|
||||||
let spf = Printf.sprintf
|
let spf = Printf.sprintf
|
||||||
|
|
@ -10,19 +10,20 @@ let sleep_inner = ref 0.1
|
||||||
let sleep_outer = ref 2.0
|
let sleep_outer = ref 2.0
|
||||||
|
|
||||||
let mk_client ~scope =
|
let mk_client ~scope =
|
||||||
Opentelemetry_cohttp_lwt.client ~scope (module Cohttp_lwt_unix.Client)
|
Opentelemetry_cohttp_lwt.client ~span:scope (module Cohttp_lwt_unix.Client)
|
||||||
|
|
||||||
let run () =
|
let run () =
|
||||||
let open Lwt.Syntax in
|
let open Lwt.Syntax in
|
||||||
|
let tracer = OT.Tracer.get_main () in
|
||||||
let rec go () =
|
let rec go () =
|
||||||
let@ scope =
|
let@ scope =
|
||||||
Otel_lwt.Trace.with_ ~kind:T.Span.Span_kind_producer "loop.outer"
|
Otel_lwt.Tracer.with_ tracer ~kind:OT.Span.Span_kind_producer "loop.outer"
|
||||||
in
|
in
|
||||||
let* () = Lwt_unix.sleep !sleep_outer in
|
let* () = Lwt_unix.sleep !sleep_outer in
|
||||||
let module C = (val mk_client ~scope) in
|
let module C = (val mk_client ~scope) in
|
||||||
(* Using the same default server O *)
|
(* Using the same default server O *)
|
||||||
let* _res, body =
|
let* _res, body =
|
||||||
C.get (Uri.of_string Opentelemetry_client.Config.default_url)
|
C.get (Uri.of_string Opentelemetry_client.Client_config.default_url)
|
||||||
in
|
in
|
||||||
let* () = Cohttp_lwt.Body.drain_body body in
|
let* () = Cohttp_lwt.Body.drain_body body in
|
||||||
go ()
|
go ()
|
||||||
|
|
@ -31,8 +32,8 @@ let run () =
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
Sys.catch_break true;
|
Sys.catch_break true;
|
||||||
T.Globals.service_name := "ocaml-otel-cohttp-client";
|
OT.Globals.service_name := "ocaml-otel-cohttp-client";
|
||||||
T.Globals.service_namespace := Some "ocaml-otel.test";
|
OT.Globals.service_namespace := Some "ocaml-otel.test";
|
||||||
|
|
||||||
let debug = ref false in
|
let debug = ref false in
|
||||||
let batch_traces = ref 400 in
|
let batch_traces = ref 400 in
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
module T = Opentelemetry
|
module OT = Opentelemetry
|
||||||
module Atomic = Opentelemetry_atomic.Atomic
|
module Atomic = Opentelemetry_atomic.Atomic
|
||||||
|
|
||||||
let spf = Printf.sprintf
|
let spf = Printf.sprintf
|
||||||
|
|
@ -23,13 +23,14 @@ let num_tr = Atomic.make 0
|
||||||
|
|
||||||
let run_job () =
|
let run_job () =
|
||||||
let@ () = Fun.protect ~finally:(fun () -> Atomic.set stop true) in
|
let@ () = Fun.protect ~finally:(fun () -> Atomic.set stop true) in
|
||||||
|
let tracer = OT.Tracer.get_main () in
|
||||||
let i = ref 0 in
|
let i = ref 0 in
|
||||||
let cnt = ref 0 in
|
let cnt = ref 0 in
|
||||||
|
|
||||||
while (not @@ Atomic.get stop) && !cnt < !n do
|
while (not @@ Atomic.get stop) && !cnt < !n do
|
||||||
let@ _scope =
|
let@ _scope =
|
||||||
Atomic.incr num_tr;
|
Atomic.incr num_tr;
|
||||||
T.Trace.with_ ~kind:T.Span.Span_kind_producer "loop.outer"
|
OT.Tracer.with_ tracer ~kind:OT.Span.Span_kind_producer "loop.outer"
|
||||||
~attrs:[ "i", `Int !i ]
|
~attrs:[ "i", `Int !i ]
|
||||||
in
|
in
|
||||||
|
|
||||||
|
|
@ -40,7 +41,7 @@ let run_job () =
|
||||||
(* parent scope is found via thread local storage *)
|
(* parent scope is found via thread local storage *)
|
||||||
let@ scope =
|
let@ scope =
|
||||||
Atomic.incr num_tr;
|
Atomic.incr num_tr;
|
||||||
T.Trace.with_ ~kind:T.Span.Span_kind_internal
|
OT.Tracer.with_ tracer ~kind:OT.Span.Span_kind_internal
|
||||||
~attrs:[ "j", `Int j ]
|
~attrs:[ "j", `Int j ]
|
||||||
"loop.inner"
|
"loop.inner"
|
||||||
in
|
in
|
||||||
|
|
@ -48,18 +49,22 @@ let run_job () =
|
||||||
Unix.sleepf !sleep_outer;
|
Unix.sleepf !sleep_outer;
|
||||||
Atomic.incr num_sleep;
|
Atomic.incr num_sleep;
|
||||||
|
|
||||||
T.Logs.(
|
let logger = OT.Logger.get_main () in
|
||||||
emit
|
OT.Emitter.emit logger
|
||||||
[
|
[
|
||||||
make_strf ~trace_id:scope.trace_id ~span_id:scope.span_id
|
OT.Log_record.make_strf ~trace_id:(OT.Span.trace_id scope)
|
||||||
~severity:Severity_number_info "inner at %d" j;
|
~span_id:(OT.Span.id scope) ~severity:Severity_number_info
|
||||||
]);
|
"inner at %d" j;
|
||||||
|
];
|
||||||
|
|
||||||
incr i;
|
incr i;
|
||||||
|
|
||||||
try
|
try
|
||||||
Atomic.incr num_tr;
|
Atomic.incr num_tr;
|
||||||
let@ _ = T.Trace.with_ ~kind:T.Span.Span_kind_internal ~scope "alloc" in
|
let@ _ =
|
||||||
|
OT.Tracer.with_ tracer ~kind:OT.Span.Span_kind_internal ~parent:scope
|
||||||
|
"alloc"
|
||||||
|
in
|
||||||
(* allocate some stuff *)
|
(* allocate some stuff *)
|
||||||
if !stress_alloc_ then (
|
if !stress_alloc_ then (
|
||||||
let _arr = Sys.opaque_identity @@ Array.make (25 * 25551) 42.0 in
|
let _arr = Sys.opaque_identity @@ Array.make (25 * 25551) 42.0 in
|
||||||
|
|
@ -72,23 +77,23 @@ let run_job () =
|
||||||
if j = 4 && !i mod 13 = 0 then failwith "oh no";
|
if j = 4 && !i mod 13 = 0 then failwith "oh no";
|
||||||
|
|
||||||
(* simulate a failure *)
|
(* simulate a failure *)
|
||||||
Opentelemetry.Scope.add_event scope (fun () ->
|
OT.Span.add_event scope (OT.Event.make "done with alloc")
|
||||||
T.Event.make "done with alloc")
|
|
||||||
with Failure _ -> ()
|
with Failure _ -> ()
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
let run () =
|
let run () =
|
||||||
T.GC_metrics.basic_setup ();
|
OT.Gc_metrics.setup_on_main_exporter ();
|
||||||
|
|
||||||
T.Metrics_callbacks.register (fun () ->
|
OT.Metrics_callbacks.with_set_added_to_main_exporter (fun set ->
|
||||||
T.Metrics.
|
OT.Metrics_callbacks.add_metrics_cb set (fun () ->
|
||||||
[
|
OT.Metrics.
|
||||||
sum ~name:"num-sleep" ~is_monotonic:true
|
[
|
||||||
[ int (Atomic.get num_sleep) ];
|
sum ~name:"num-sleep" ~is_monotonic:true
|
||||||
sum ~name:"otel.bytes-sent" ~is_monotonic:true ~unit_:"B"
|
[ int (Atomic.get num_sleep) ];
|
||||||
[ int (Opentelemetry_client_ocurl.n_bytes_sent ()) ];
|
sum ~name:"otel.bytes-sent" ~is_monotonic:true ~unit_:"B"
|
||||||
]);
|
[ int (Opentelemetry_client_ocurl.n_bytes_sent ()) ];
|
||||||
|
]));
|
||||||
|
|
||||||
let n_jobs = max 1 !n_jobs in
|
let n_jobs = max 1 !n_jobs in
|
||||||
Printf.printf "run %d jobs\n%!" n_jobs;
|
Printf.printf "run %d jobs\n%!" n_jobs;
|
||||||
|
|
@ -101,8 +106,8 @@ let run () =
|
||||||
Array.iter Thread.join jobs
|
Array.iter Thread.join jobs
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
T.Globals.service_name := "t1";
|
OT.Globals.service_name := "t1";
|
||||||
T.Globals.service_namespace := Some "ocaml-otel.test";
|
OT.Globals.service_namespace := Some "ocaml-otel.test";
|
||||||
let ts_start = Unix.gettimeofday () in
|
let ts_start = Unix.gettimeofday () in
|
||||||
|
|
||||||
let debug = ref false in
|
let debug = ref false in
|
||||||
|
|
|
||||||
|
|
@ -82,12 +82,14 @@ let run_job clock _job_id iterations : unit =
|
||||||
let run env proc iterations () : unit =
|
let run env proc iterations () : unit =
|
||||||
OT.Gc_metrics.setup_on_main_exporter ();
|
OT.Gc_metrics.setup_on_main_exporter ();
|
||||||
|
|
||||||
OT.Metrics_callbacks.register (fun () ->
|
OT.Metrics_callbacks.(
|
||||||
OT.Metrics.
|
with_set_added_to_main_exporter (fun set ->
|
||||||
[
|
add_metrics_cb set (fun () ->
|
||||||
sum ~name:"num-sleep" ~is_monotonic:true
|
OT.Metrics.
|
||||||
[ int (Atomic.get num_sleep) ];
|
[
|
||||||
]);
|
sum ~name:"num-sleep" ~is_monotonic:true
|
||||||
|
[ int (Atomic.get num_sleep) ];
|
||||||
|
])));
|
||||||
|
|
||||||
let n_jobs = max 1 !n_jobs in
|
let n_jobs = max 1 !n_jobs in
|
||||||
Printf.printf "run %d jobs in proc %d\n%!" n_jobs proc;
|
Printf.printf "run %d jobs in proc %d\n%!" n_jobs proc;
|
||||||
|
|
@ -172,4 +174,4 @@ let () =
|
||||||
Eio.Fiber.fork ~sw @@ fun () ->
|
Eio.Fiber.fork ~sw @@ fun () ->
|
||||||
Eio.Domain_manager.run dm (run env proc !n_iterations)
|
Eio.Domain_manager.run dm (run env proc !n_iterations)
|
||||||
done));
|
done));
|
||||||
Opentelemetry.Collector.remove_backend () ~on_done:ignore
|
Opentelemetry.Main_exporter.remove () ~on_done:ignore
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue