mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-10 12:45:45 -04:00
better debug
This commit is contained in:
parent
84be273b76
commit
0a8e60ba46
1 changed files with 10 additions and 8 deletions
|
|
@ -361,11 +361,11 @@ let mk_emitter ~stop ~(config : Config.t) () : (module EMITTER) =
|
||||||
send_logs_http httpc encoder l;
|
send_logs_http httpc encoder l;
|
||||||
true
|
true
|
||||||
|
|
||||||
let[@inline] guard_exn_ f =
|
let[@inline] guard_exn_ where f =
|
||||||
try f ()
|
try f ()
|
||||||
with e ->
|
with e ->
|
||||||
Printf.eprintf "opentelemetry-curl: uncaught exception: %s\n%!"
|
Printf.eprintf "opentelemetry-curl: uncaught exception in %s: %s\n%!"
|
||||||
(Printexc.to_string e)
|
where (Printexc.to_string e)
|
||||||
|
|
||||||
let emit_all_force (httpc : Httpc.t) encoder =
|
let emit_all_force (httpc : Httpc.t) encoder =
|
||||||
let now = Mtime_clock.now () in
|
let now = Mtime_clock.now () in
|
||||||
|
|
@ -413,7 +413,7 @@ let mk_emitter ~stop ~(config : Config.t) () : (module EMITTER) =
|
||||||
let httpc = Httpc.create () in
|
let httpc = Httpc.create () in
|
||||||
let encoder = Pbrt.Encoder.create () in
|
let encoder = Pbrt.Encoder.create () in
|
||||||
while not @@ Atomic.get stop do
|
while not @@ Atomic.get stop do
|
||||||
let@ () = guard_exn_ in
|
let@ () = guard_exn_ "bg thread (main loop)" in
|
||||||
|
|
||||||
let now = Mtime_clock.now () in
|
let now = Mtime_clock.now () in
|
||||||
let do_metrics = emit_metrics_maybe ~now httpc encoder in
|
let do_metrics = emit_metrics_maybe ~now httpc encoder in
|
||||||
|
|
@ -425,7 +425,7 @@ let mk_emitter ~stop ~(config : Config.t) () : (module EMITTER) =
|
||||||
Condition.wait cond m
|
Condition.wait cond m
|
||||||
done;
|
done;
|
||||||
(* flush remaining events once we exit *)
|
(* flush remaining events once we exit *)
|
||||||
let@ () = guard_exn_ in
|
let@ () = guard_exn_ "bg thread (cleanup)" in
|
||||||
emit_all_force httpc encoder;
|
emit_all_force httpc encoder;
|
||||||
Httpc.cleanup httpc
|
Httpc.cleanup httpc
|
||||||
in
|
in
|
||||||
|
|
@ -490,14 +490,14 @@ let mk_emitter ~stop ~(config : Config.t) () : (module EMITTER) =
|
||||||
the emit functions. *)
|
the emit functions. *)
|
||||||
|
|
||||||
let push_trace e =
|
let push_trace e =
|
||||||
let@ () = guard_exn_ in
|
let@ () = guard_exn_ "push trace" in
|
||||||
Batch.push' batch_traces e;
|
Batch.push' batch_traces e;
|
||||||
let now = Mtime_clock.now () in
|
let now = Mtime_clock.now () in
|
||||||
let@ () = Lock.with_lock in
|
let@ () = Lock.with_lock in
|
||||||
ignore (emit_traces_maybe ~now httpc encoder : bool)
|
ignore (emit_traces_maybe ~now httpc encoder : bool)
|
||||||
|
|
||||||
let push_metrics e =
|
let push_metrics e =
|
||||||
let@ () = guard_exn_ in
|
let@ () = guard_exn_ "push metrics" in
|
||||||
if Atomic.get needs_gc_metrics then sample_gc_metrics ();
|
if Atomic.get needs_gc_metrics then sample_gc_metrics ();
|
||||||
Batch.push' batch_metrics e;
|
Batch.push' batch_metrics e;
|
||||||
let now = Mtime_clock.now () in
|
let now = Mtime_clock.now () in
|
||||||
|
|
@ -505,7 +505,7 @@ let mk_emitter ~stop ~(config : Config.t) () : (module EMITTER) =
|
||||||
ignore (emit_metrics_maybe ~now httpc encoder : bool)
|
ignore (emit_metrics_maybe ~now httpc encoder : bool)
|
||||||
|
|
||||||
let push_logs e =
|
let push_logs e =
|
||||||
let@ () = guard_exn_ in
|
let@ () = guard_exn_ "push logs" in
|
||||||
Batch.push' batch_logs e;
|
Batch.push' batch_logs e;
|
||||||
let now = Mtime_clock.now () in
|
let now = Mtime_clock.now () in
|
||||||
let@ () = Lock.with_lock in
|
let@ () = Lock.with_lock in
|
||||||
|
|
@ -575,6 +575,8 @@ end)
|
||||||
Mtime.Span.compare elapsed timeout_sent_metrics > 0
|
Mtime.Span.compare elapsed timeout_sent_metrics > 0
|
||||||
in
|
in
|
||||||
|
|
||||||
|
(* there is a possible race condition here, as several threads might update
|
||||||
|
metrics at the same time. But that's harmless. *)
|
||||||
if add_own_metrics then (
|
if add_own_metrics then (
|
||||||
let open OT.Metrics in
|
let open OT.Metrics in
|
||||||
Atomic.set last_sent_metrics now;
|
Atomic.set last_sent_metrics now;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue