add ?enable to the ocurl client

This commit is contained in:
Simon Cruanes 2022-03-22 11:33:12 -04:00
parent 000292cd17
commit bcbb07027f
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 15 additions and 8 deletions

View file

@ -489,10 +489,14 @@ let setup_ ~(config:Config.t) () =
Opentelemetry.Collector.backend := Some (module B);
B.cleanup
let setup ?(config=Config.make()) () =
let cleanup = setup_ ~config () in
at_exit cleanup
let setup ?(config=Config.make()) ?(enable=true) () =
if enable then (
let cleanup = setup_ ~config () in
at_exit cleanup
)
let with_setup ?(config=Config.make()) () f =
let cleanup = setup_ ~config () in
Fun.protect ~finally:cleanup f
let with_setup ?(config=Config.make()) ?(enable=true) () f =
if enable then (
let cleanup = setup_ ~config () in
Fun.protect ~finally:cleanup f
) else f()

View file

@ -60,10 +60,13 @@ module Config : sig
val pp : Format.formatter -> t -> unit
end
val setup : ?config:Config.t -> unit -> unit
val setup : ?config:Config.t -> ?enable:bool -> unit -> unit
(** Setup endpoint. This modifies {!Opentelemetry.Collector.backend}.
@param enable actually setup the backend (default true). This can
be used to enable/disable the setup depending on CLI arguments
or environment.
@param config configuration to use *)
val with_setup : ?config:Config.t -> unit -> (unit -> 'a) -> 'a
val with_setup : ?config:Config.t -> ?enable:bool -> unit -> (unit -> 'a) -> 'a
(** [with_setup () f] is like [setup(); f()] but takes care of cleaning up
after [f()] returns. *)