Skip to content

Commit cd8e1ea

Browse files
committed
Add interface for flush spans and exit the export thread
Signed-off-by: Vincent Liu <shuntian.liu2@cloud.com>
1 parent 7ac88b9 commit cd8e1ea

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

ocaml/libs/tracing/tracing.ml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*)
1414
module D = Debug.Make (struct let name = "tracing" end)
1515

16+
module Delay = Xapi_stdext_threads.Threadext.Delay
1617
open D
1718

1819
type endpoint = Bugtool | Url of Uri.t
@@ -803,19 +804,30 @@ module Export = struct
803804
|> List.concat_map (fun x -> TracerProvider.get_endpoints x)
804805
|> List.iter (export_to_endpoint parent span_list)
805806

807+
let delay = Delay.make ()
808+
809+
(* Note this signal will flush the spans and terminate the exporter thread *)
810+
let signal () = Delay.signal delay
811+
806812
let main () =
807813
enable_span_garbage_collector () ;
808814
Thread.create
809815
(fun () ->
810816
while true do
811817
debug "Tracing: Waiting %d seconds before exporting spans"
812818
(int_of_float !export_interval) ;
813-
Thread.delay !export_interval ;
819+
if not (Delay.wait delay !export_interval) then (
820+
debug "Tracing: we are signaled, export spans now and exit" ;
821+
flush_spans () ;
822+
raise Thread.Exit
823+
) ;
814824
flush_spans ()
815825
done
816826
)
817827
()
818828
end
819829
end
820830

831+
let flush_and_exit = Export.Destination.signal
832+
821833
let main = Export.Destination.main

ocaml/libs/tracing/tracing.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,6 @@ val set_observe : bool -> unit
152152

153153
val validate_attribute : string * string -> bool
154154

155+
val flush_and_exit : unit -> unit
156+
155157
val main : unit -> Thread.t

0 commit comments

Comments
 (0)