diff --git a/ocaml/forkexecd/lib/dune b/ocaml/forkexecd/lib/dune index 3ed1d4eb891..3d132e8ed76 100644 --- a/ocaml/forkexecd/lib/dune +++ b/ocaml/forkexecd/lib/dune @@ -12,6 +12,7 @@ xapi-log xapi-stdext-pervasives xapi-stdext-unix + xapi-tracing ) (preprocess (pps ppx_deriving_rpc))) diff --git a/ocaml/forkexecd/lib/forkhelpers.ml b/ocaml/forkexecd/lib/forkhelpers.ml index 15fb4bca6c5..b86a9e74642 100644 --- a/ocaml/forkexecd/lib/forkhelpers.ml +++ b/ocaml/forkexecd/lib/forkhelpers.ml @@ -36,6 +36,10 @@ let test_path = let runtime_path = Option.value ~default:"/var" test_path +let with_tracing ?traceparent ~name f = + let name = "forkhelpers" ^ "." ^ name in + Tracing.with_tracing ?parent:traceparent ~name f + let finally = Xapi_stdext_pervasives.Pervasiveext.finally type pidty = Unix.file_descr * int @@ -300,8 +304,9 @@ let safe_close_and_exec ?env stdin stdout stderr ) close_fds -let execute_command_get_output_inner ?env ?stdin ?(syslog_stdout = NoSyslogging) - ?(redirect_stderr_to_stdout = false) ?(timeout = -1.0) cmd args = +let execute_command_get_output_inner ?traceparent ?env ?stdin + ?(syslog_stdout = NoSyslogging) ?(redirect_stderr_to_stdout = false) + ?(timeout = -1.0) cmd args = let to_close = ref [] in let close fd = if List.mem fd !to_close then ( @@ -357,10 +362,12 @@ let execute_command_get_output_inner ?env ?stdin ?(syslog_stdout = NoSyslogging) ) (fun () -> List.iter Unix.close !to_close) -let execute_command_get_output ?env ?(syslog_stdout = NoSyslogging) +let execute_command_get_output ?traceparent ?env ?(syslog_stdout = NoSyslogging) ?(redirect_stderr_to_stdout = false) ?timeout cmd args = - execute_command_get_output_inner ?env ?stdin:None ?timeout ~syslog_stdout - ~redirect_stderr_to_stdout cmd args + with_tracing ~traceparent ~name:"execute_command_get_output" + @@ fun traceparent -> + execute_command_get_output_inner ?traceparent ?env ?stdin:None ?timeout + ~syslog_stdout ~redirect_stderr_to_stdout cmd args let execute_command_get_output_send_stdin ?env ?(syslog_stdout = NoSyslogging) ?(redirect_stderr_to_stdout = false) ?timeout cmd args stdin = diff --git a/ocaml/forkexecd/lib/forkhelpers.mli b/ocaml/forkexecd/lib/forkhelpers.mli index 48832726c02..0dd12a4d178 100644 --- a/ocaml/forkexecd/lib/forkhelpers.mli +++ b/ocaml/forkexecd/lib/forkhelpers.mli @@ -44,7 +44,8 @@ val default_path : string list val default_path_env_pair : string array val execute_command_get_output : - ?env:string array + ?traceparent:Tracing.Span.t + -> ?env:string array -> ?syslog_stdout:syslog_stdout_t -> ?redirect_stderr_to_stdout:bool -> ?timeout:float diff --git a/ocaml/xapi/sm_exec.ml b/ocaml/xapi/sm_exec.ml index a55b61d72f9..eba79aa999c 100644 --- a/ocaml/xapi/sm_exec.ml +++ b/ocaml/xapi/sm_exec.ml @@ -363,7 +363,8 @@ let exec_xmlrpc ~dbg ?context:_ ?(needs_session = true) (driver : string) ~component:Xapi_observer_components.SMApi ~traceparent ~exe ~args in - Forkhelpers.execute_command_get_output ?env exe args + Forkhelpers.execute_command_get_output ?traceparent:di.tracing + ?env exe args in try (Xml.parse_string output, stderr) with e ->