mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-08 03:47:59 -04:00
fix metrics_callbacks' API to make it easier
This commit is contained in:
parent
fe416cfbdd
commit
68761faadb
2 changed files with 19 additions and 1 deletions
|
|
@ -22,10 +22,20 @@ let add_to_exporter (exp : Exporter.t) (self : t) =
|
|||
in
|
||||
Exporter.on_tick exp on_tick
|
||||
|
||||
let with_set_added_to_exporter (exp : Exporter.t) (f : t -> 'a) : 'a =
|
||||
let set = create () in
|
||||
add_to_exporter exp set;
|
||||
f set
|
||||
|
||||
let with_set_added_to_main_exporter (f : t -> unit) : unit =
|
||||
match Main_exporter.get () with
|
||||
| None -> ()
|
||||
| Some exp -> with_set_added_to_exporter exp f
|
||||
|
||||
module Main_set = struct
|
||||
let cur_set_ : t option Atomic.t = Atomic.make None
|
||||
|
||||
let rec get () =
|
||||
let rec get () : t =
|
||||
match Atomic.get cur_set_ with
|
||||
| Some s -> s
|
||||
| None ->
|
||||
|
|
|
|||
|
|
@ -19,6 +19,14 @@ val add_metrics_cb : t -> (unit -> Metrics.t list) -> unit
|
|||
val add_to_exporter : Exporter.t -> t -> unit
|
||||
(** Make sure we export metrics at every [tick] of the exporter *)
|
||||
|
||||
val with_set_added_to_exporter : Exporter.t -> (t -> 'a) -> 'a
|
||||
(** [with_set_added_to_exporter exp f] creates a set, adds it to the exporter,
|
||||
and calls [f] on it *)
|
||||
|
||||
val with_set_added_to_main_exporter : (t -> unit) -> unit
|
||||
(** If there is a main exporter, add a set to it and call [f set], else do not
|
||||
call [f] at all *)
|
||||
|
||||
module Main_set : sig
|
||||
val get : unit -> t
|
||||
(** The global set *)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue