mirror of
https://github.com/ocaml-tracing/ocaml-trace.git
synced 2026-03-09 04:17:56 -04:00
core: add on_init callback to collector
This commit is contained in:
parent
8e2bb5bc83
commit
40b44349e7
2 changed files with 10 additions and 2 deletions
|
|
@ -58,6 +58,7 @@ module Callbacks = struct
|
||||||
unit;
|
unit;
|
||||||
extension: 'st -> extension_event -> unit;
|
extension: 'st -> extension_event -> unit;
|
||||||
(** Collector-specific extension *)
|
(** Collector-specific extension *)
|
||||||
|
init: 'st -> unit; (** Called on initialization *)
|
||||||
shutdown: 'st -> unit;
|
shutdown: 'st -> unit;
|
||||||
(** Shutdown collector, possibly waiting for it to finish sending data.
|
(** Shutdown collector, possibly waiting for it to finish sending data.
|
||||||
*)
|
*)
|
||||||
|
|
@ -67,7 +68,8 @@ module Callbacks = struct
|
||||||
(** Helper to create backends in a future-proof way *)
|
(** Helper to create backends in a future-proof way *)
|
||||||
let make ~enter_span ~exit_span ?(current_span = fun _ -> None)
|
let make ~enter_span ~exit_span ?(current_span = fun _ -> None)
|
||||||
~add_data_to_span ~message ~counter_int ~counter_float
|
~add_data_to_span ~message ~counter_int ~counter_float
|
||||||
?(extension = fun _ _ -> ()) ?(shutdown = ignore) () : _ t =
|
?(extension = fun _ _ -> ()) ?(init = ignore) ?(shutdown = ignore) () :
|
||||||
|
_ t =
|
||||||
{
|
{
|
||||||
enter_span;
|
enter_span;
|
||||||
exit_span;
|
exit_span;
|
||||||
|
|
@ -77,6 +79,7 @@ module Callbacks = struct
|
||||||
counter_int;
|
counter_int;
|
||||||
counter_float;
|
counter_float;
|
||||||
extension;
|
extension;
|
||||||
|
init;
|
||||||
shutdown;
|
shutdown;
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,12 @@ let setup_collector c : unit =
|
||||||
| C_none -> not (A.compare_and_set collector cur c)
|
| C_none -> not (A.compare_and_set collector cur c)
|
||||||
do
|
do
|
||||||
()
|
()
|
||||||
done
|
done;
|
||||||
|
|
||||||
|
(* initialize collector *)
|
||||||
|
match c with
|
||||||
|
| C_none -> ()
|
||||||
|
| C_some (st, cb) -> cb.init st
|
||||||
|
|
||||||
let shutdown () =
|
let shutdown () =
|
||||||
match A.exchange collector C_none with
|
match A.exchange collector C_none with
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue