core: add on_init callback to collector

This commit is contained in:
Simon Cruanes 2026-01-14 21:46:21 -05:00
parent 8e2bb5bc83
commit 40b44349e7
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 10 additions and 2 deletions

View file

@ -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

View file

@ -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