mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-08 20:07:55 -04:00
catch errors in backend
This commit is contained in:
parent
b03ff26ba6
commit
000292cd17
1 changed files with 25 additions and 3 deletions
|
|
@ -276,6 +276,11 @@ let mk_push (type a) ?batch () : (module PUSH with type elt = a) * (on_full_cb -
|
||||||
in
|
in
|
||||||
push, ((:=) on_full)
|
push, ((:=) on_full)
|
||||||
|
|
||||||
|
|
||||||
|
(* make an emitter.
|
||||||
|
|
||||||
|
exceptions inside should be caught, see
|
||||||
|
https://opentelemetry.io/docs/reference/specification/error-handling/ *)
|
||||||
let mk_emitter ~(config:Config.t) () : (module EMITTER) =
|
let mk_emitter ~(config:Config.t) () : (module EMITTER) =
|
||||||
let open Proto in
|
let open Proto in
|
||||||
|
|
||||||
|
|
@ -355,11 +360,20 @@ let mk_emitter ~(config:Config.t) () : (module EMITTER) =
|
||||||
) else false
|
) else false
|
||||||
in
|
in
|
||||||
|
|
||||||
|
let[@inline] guard f =
|
||||||
|
try f()
|
||||||
|
with e ->
|
||||||
|
Printf.eprintf "opentelemetry-curl: uncaught exception: %s\n%!"
|
||||||
|
(Printexc.to_string e)
|
||||||
|
in
|
||||||
|
|
||||||
let emit_all_force () =
|
let emit_all_force () =
|
||||||
|
let@ () = guard in
|
||||||
ignore (emit_traces ~force:true () : bool);
|
ignore (emit_traces ~force:true () : bool);
|
||||||
ignore (emit_metrics ~force:true () : bool);
|
ignore (emit_metrics ~force:true () : bool);
|
||||||
in
|
in
|
||||||
|
|
||||||
|
|
||||||
if config.thread then (
|
if config.thread then (
|
||||||
begin
|
begin
|
||||||
let m = Mutex.create() in
|
let m = Mutex.create() in
|
||||||
|
|
@ -373,6 +387,7 @@ let mk_emitter ~(config:Config.t) () : (module EMITTER) =
|
||||||
|
|
||||||
let bg_thread () =
|
let bg_thread () =
|
||||||
while !continue do
|
while !continue do
|
||||||
|
let@ () = guard in
|
||||||
if emit_metrics () then ()
|
if emit_metrics () then ()
|
||||||
else if emit_traces () then ()
|
else if emit_traces () then ()
|
||||||
else (
|
else (
|
||||||
|
|
@ -382,9 +397,12 @@ let mk_emitter ~(config:Config.t) () : (module EMITTER) =
|
||||||
)
|
)
|
||||||
done;
|
done;
|
||||||
(* flush remaining events *)
|
(* flush remaining events *)
|
||||||
|
begin
|
||||||
|
let@ () = guard in
|
||||||
ignore (emit_traces ~force:true () : bool);
|
ignore (emit_traces ~force:true () : bool);
|
||||||
ignore (emit_metrics ~force:true () : bool);
|
ignore (emit_metrics ~force:true () : bool);
|
||||||
C.cleanup();
|
C.cleanup();
|
||||||
|
end
|
||||||
in
|
in
|
||||||
|
|
||||||
let _: Thread.t = Thread.create bg_thread () in
|
let _: Thread.t = Thread.create bg_thread () in
|
||||||
|
|
@ -424,11 +442,15 @@ let mk_emitter ~(config:Config.t) () : (module EMITTER) =
|
||||||
|
|
||||||
let module M = struct
|
let module M = struct
|
||||||
let push_trace e ~over =
|
let push_trace e ~over =
|
||||||
|
let@() = guard in
|
||||||
E_trace.push (e,over);
|
E_trace.push (e,over);
|
||||||
if batch_timeout() then emit_all_force()
|
if batch_timeout() then emit_all_force()
|
||||||
|
|
||||||
let push_metrics e ~over =
|
let push_metrics e ~over =
|
||||||
|
let@() = guard in
|
||||||
E_metrics.push (e,over);
|
E_metrics.push (e,over);
|
||||||
if batch_timeout() then emit_all_force()
|
if batch_timeout() then emit_all_force()
|
||||||
|
|
||||||
let cleanup = cleanup
|
let cleanup = cleanup
|
||||||
end in
|
end in
|
||||||
(module M)
|
(module M)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue