mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-08 03:47:59 -04:00
ocurl: add an ?after_shutdown callback
This commit is contained in:
parent
239d9d5aec
commit
bfde7700e8
2 changed files with 14 additions and 5 deletions
|
|
@ -97,13 +97,16 @@ let create_exporter ?(config = Config.make ()) () : OTEL.Exporter.t =
|
||||||
|
|
||||||
let create_backend = create_exporter
|
let create_backend = create_exporter
|
||||||
|
|
||||||
let shutdown_and_wait (self : OTEL.Exporter.t) : unit =
|
let shutdown_and_wait ?(after_shutdown = ignore) (self : OTEL.Exporter.t) : unit
|
||||||
|
=
|
||||||
let open Opentelemetry_client in
|
let open Opentelemetry_client in
|
||||||
let sq = Sync_queue.create () in
|
let sq = Sync_queue.create () in
|
||||||
OTEL.Aswitch.on_turn_off (OTEL.Exporter.active self) (fun () ->
|
OTEL.Aswitch.on_turn_off (OTEL.Exporter.active self) (fun () ->
|
||||||
Sync_queue.push sq ());
|
Sync_queue.push sq ());
|
||||||
OTEL.Exporter.shutdown self;
|
OTEL.Exporter.shutdown self;
|
||||||
Sync_queue.pop sq
|
Sync_queue.pop sq;
|
||||||
|
after_shutdown self;
|
||||||
|
()
|
||||||
|
|
||||||
let setup_ ?(config : Config.t = Config.make ()) () : OTEL.Exporter.t =
|
let setup_ ?(config : Config.t = Config.make ()) () : OTEL.Exporter.t =
|
||||||
let exporter = create_exporter ~config () in
|
let exporter = create_exporter ~config () in
|
||||||
|
|
@ -133,10 +136,10 @@ let remove_backend = remove_exporter
|
||||||
let setup ?config ?(enable = true) () =
|
let setup ?config ?(enable = true) () =
|
||||||
if enable then ignore (setup_ ?config () : OTEL.Exporter.t)
|
if enable then ignore (setup_ ?config () : OTEL.Exporter.t)
|
||||||
|
|
||||||
let with_setup ?config ?(enable = true) () f =
|
let with_setup ?after_shutdown ?config ?(enable = true) () f =
|
||||||
if enable then (
|
if enable then (
|
||||||
let exp = setup_ ?config () in
|
let exp = setup_ ?config () in
|
||||||
Fun.protect f ~finally:(fun () -> shutdown_and_wait exp)
|
Fun.protect f ~finally:(fun () -> shutdown_and_wait ?after_shutdown exp)
|
||||||
) else
|
) else
|
||||||
f ()
|
f ()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,12 @@ val remove_backend : unit -> unit
|
||||||
[@@deprecated "use remove_exporter"]
|
[@@deprecated "use remove_exporter"]
|
||||||
(** @since 0.12 *)
|
(** @since 0.12 *)
|
||||||
|
|
||||||
val with_setup : ?config:Config.t -> ?enable:bool -> unit -> (unit -> 'a) -> 'a
|
val with_setup :
|
||||||
|
?after_shutdown:(Opentelemetry.Exporter.t -> unit) ->
|
||||||
|
?config:Config.t ->
|
||||||
|
?enable:bool ->
|
||||||
|
unit ->
|
||||||
|
(unit -> 'a) ->
|
||||||
|
'a
|
||||||
(** [with_setup () f] is like [setup(); f()] but takes care of cleaning up after
|
(** [with_setup () f] is like [setup(); f()] but takes care of cleaning up after
|
||||||
[f()] returns See {!setup} for more details. *)
|
[f()] returns See {!setup} for more details. *)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue