From 65b18b1db370ce58ded0f1d55b977909edbd0504 Mon Sep 17 00:00:00 2001 From: Steven Woods Date: Mon, 13 Nov 2023 17:03:13 +0000 Subject: [PATCH] CA-378591: Clear span tables when all observers are disabled Signed-off-by: Steven Woods --- ocaml/libs/tracing/tracing.ml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/ocaml/libs/tracing/tracing.ml b/ocaml/libs/tracing/tracing.ml index 4555d646d32..78036e1f319 100644 --- a/ocaml/libs/tracing/tracing.ml +++ b/ocaml/libs/tracing/tracing.ml @@ -444,6 +444,9 @@ let lock = Mutex.create () let tracer_providers = Hashtbl.create 100 +let get_tracer_providers () = + Hashtbl.fold (fun _ provider acc -> provider :: acc) tracer_providers [] + let set ?enabled ?attributes ?endpoints ~uuid () = Xapi_stdext_threads.Threadext.Mutex.execute lock (fun () -> let provider = @@ -465,7 +468,16 @@ let set ?enabled ?attributes ?endpoints ~uuid () = (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 + Xapi_stdext_threads.Threadext.Mutex.execute Spans.lock (fun () -> + Hashtbl.clear Spans.spans ; + Hashtbl.clear Spans.finished_spans + ) let create ~enabled ~attributes ~endpoints ~name_label ~uuid = let endpoints = List.map endpoint_of_string endpoints in @@ -486,9 +498,6 @@ let destroy ~uuid = Hashtbl.remove tracer_providers uuid ) -let get_tracer_providers () = - Hashtbl.fold (fun _ provider acc -> provider :: acc) tracer_providers [] - let get_tracer ~name = let providers = Xapi_stdext_threads.Threadext.Mutex.execute lock (fun () ->