Skip to content

Commit

Permalink
Merge pull request xapi-project#5244 from snwoods/private/stevenwo/CA…
Browse files Browse the repository at this point in the history
…-378591

CA-378591: Clear span tables when all observers are disabled
  • Loading branch information
snwoods committed Nov 15, 2023
2 parents 1d3da69 + 65b18b1 commit 08e8ec0
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions ocaml/libs/tracing/tracing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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
Expand All @@ -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 () ->
Expand Down

0 comments on commit 08e8ec0

Please sign in to comment.