diff --git a/ocaml/libs/tracing/tracing.ml b/ocaml/libs/tracing/tracing.ml index d56403b1401..cf869e1be61 100644 --- a/ocaml/libs/tracing/tracing.ml +++ b/ocaml/libs/tracing/tracing.ml @@ -88,8 +88,6 @@ let observe = Atomic.make false let set_observe = Atomic.set observe -let get_observe () = Atomic.get observe - module SpanKind = struct type t = Server | Consumer | Client | Producer | Internal [@@deriving rpcty] @@ -563,20 +561,18 @@ let set ?enabled ?attributes ?endpoints ~uuid () = failwith (Printf.sprintf "The TracerProvider : %s does not exist" uuid) in - Hashtbl.replace tracer_providers uuid provider - ) ; - if - List.for_all - (fun provider -> not provider.TracerProvider.enabled) - (get_tracer_providers ()) - then ( - set_observe false ; - Xapi_stdext_threads.Threadext.Mutex.execute Spans.lock (fun () -> + Hashtbl.replace tracer_providers uuid provider ; + if + List.for_all + (fun provider -> not provider.TracerProvider.enabled) + (get_tracer_providers ()) + then ( + set_observe false ; Hashtbl.clear Spans.spans ; Hashtbl.clear Spans.finished_spans - ) - ) else if not (get_observe ()) then - set_observe true + ) else + set_observe true + ) let create ~enabled ~attributes ~endpoints ~name_label ~uuid = let endpoints = List.map endpoint_of_string endpoints in @@ -618,7 +614,7 @@ let enable_span_garbage_collector ?(timeout = 86400.) () = Spans.GC.initialise_thread ~timeout let with_tracing ?(attributes = []) ?(parent = None) ~name f = - if not (get_observe ()) then + if not (Atomic.get observe) then f None else let tracer = get_tracer ~name in diff --git a/ocaml/libs/tracing/tracing.mli b/ocaml/libs/tracing/tracing.mli index fda20b0aa04..b7f33b6d051 100644 --- a/ocaml/libs/tracing/tracing.mli +++ b/ocaml/libs/tracing/tracing.mli @@ -176,8 +176,6 @@ val with_tracing : val set_observe : bool -> unit -val get_observe : unit -> bool - val validate_attribute : string * string -> bool (** [EnvHelpers] module is a helper module for the tracing library to easily diff --git a/ocaml/xapi/xapi_observer.ml b/ocaml/xapi/xapi_observer.ml index f20a411587f..d0fb164f6fd 100644 --- a/ocaml/xapi/xapi_observer.ml +++ b/ocaml/xapi/xapi_observer.ml @@ -309,7 +309,7 @@ module Dom0ObserverConfig (ObserverComponent : OBSERVER_COMPONENT) : let update_config ~__context ~observer ~uuid = if Db.Observer.get_enabled ~__context ~self:observer then ( - if not (Tracing.get_observe ()) then Tracing.set_observe true ; + Tracing.set_observe true ; let observer_config = ObserverConfig.config_of_observer ~__context ~component:ObserverComponent.component ~observer