mirror of
https://github.com/ocaml-tracing/ocaml-trace.git
synced 2026-03-08 03:47:57 -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;
|
||||
extension: 'st -> extension_event -> unit;
|
||||
(** Collector-specific extension *)
|
||||
init: 'st -> unit; (** Called on initialization *)
|
||||
shutdown: 'st -> unit;
|
||||
(** 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 *)
|
||||
let make ~enter_span ~exit_span ?(current_span = fun _ -> None)
|
||||
~add_data_to_span ~message ~counter_int ~counter_float
|
||||
?(extension = fun _ _ -> ()) ?(shutdown = ignore) () : _ t =
|
||||
?(extension = fun _ _ -> ()) ?(init = ignore) ?(shutdown = ignore) () :
|
||||
_ t =
|
||||
{
|
||||
enter_span;
|
||||
exit_span;
|
||||
|
|
@ -77,6 +79,7 @@ module Callbacks = struct
|
|||
counter_int;
|
||||
counter_float;
|
||||
extension;
|
||||
init;
|
||||
shutdown;
|
||||
}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -128,7 +128,12 @@ let setup_collector c : unit =
|
|||
| C_none -> not (A.compare_and_set collector cur c)
|
||||
do
|
||||
()
|
||||
done
|
||||
done;
|
||||
|
||||
(* initialize collector *)
|
||||
match c with
|
||||
| C_none -> ()
|
||||
| C_some (st, cb) -> cb.init st
|
||||
|
||||
let shutdown () =
|
||||
match A.exchange collector C_none with
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue