From 3c08842e2de45d23a6f9b4f59a64e01620a9ce31 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Wed, 17 Dec 2025 13:59:58 -0500 Subject: [PATCH] fixes and cleanup in cohttp-eio client --- .../opentelemetry_client_cohttp_eio.ml | 18 ++++++++---------- .../opentelemetry_client_cohttp_eio.mli | 10 +++++++--- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/client-cohttp-eio/opentelemetry_client_cohttp_eio.ml b/src/client-cohttp-eio/opentelemetry_client_cohttp_eio.ml index f7f21def..49d8dfa2 100644 --- a/src/client-cohttp-eio/opentelemetry_client_cohttp_eio.ml +++ b/src/client-cohttp-eio/opentelemetry_client_cohttp_eio.ml @@ -1,5 +1,3 @@ -open Eio.Std - (* https://github.com/open-telemetry/oteps/blob/main/text/0035-opentelemetry-protocol.md https://github.com/open-telemetry/oteps/blob/main/text/0099-otlp-http.md @@ -48,7 +46,9 @@ struct ensure it runs in the Eio thread? *) Eio.Condition.broadcast self.cond - let delete = ignore + let delete self = + trigger self; + () let wait self = Eio.Mutex.lock self.mutex; @@ -193,12 +193,10 @@ let remove_exporter () = let remove_backend = remove_exporter -let with_setup ?config ?(enable = true) f env = - if enable then +let with_setup ?config ?(enable = true) env f = + if enable then ( Eio.Switch.run @@ fun sw -> - snd - @@ Fiber.pair - (fun () -> setup_ ~sw ?config env) - (fun () -> Fun.protect ~finally:(fun () -> remove_backend ()) f) - else + setup_ ~sw ?config env; + Fun.protect f ~finally:remove_exporter + ) else f () diff --git a/src/client-cohttp-eio/opentelemetry_client_cohttp_eio.mli b/src/client-cohttp-eio/opentelemetry_client_cohttp_eio.mli index cae9dde1..6a6aede9 100644 --- a/src/client-cohttp-eio/opentelemetry_client_cohttp_eio.mli +++ b/src/client-cohttp-eio/opentelemetry_client_cohttp_eio.mli @@ -49,11 +49,15 @@ val setup : an atomic boolean. When it becomes true, background threads will all stop after a little while. *) -val remove_backend : unit -> unit -(** Shutdown current backend +val remove_exporter : unit -> unit +(** Shutdown current exporter @since 0.12 *) +val remove_backend : unit -> unit +[@@deprecated "use remove_exporter"] +(** @since 0.12 *) + val with_setup : - ?config:Config.t -> ?enable:bool -> (unit -> 'a) -> Eio_unix.Stdenv.base -> 'a + ?config:Config.t -> ?enable:bool -> Eio_unix.Stdenv.base -> (unit -> 'a) -> 'a (** [with_setup () f] is like [setup(); f()] but takes care of cleaning up after [f()] returns See {!setup} for more details. *)