Skip to content

Commit

Permalink
CP-48195: Remove code duplication.
Browse files Browse the repository at this point in the history
Removes code duplication in `storage_mux.ml` by using the
already existing `with_dbg` implementation from `debuginfo` module.

This should lower the chances of unintentionally introducing bugs by
having to maintain two version of the same functions. e.g. Not using the
no op when tracing is disabled and generating unwanted warning messages.

Signed-off-by: Gabriel Buica <[email protected]>
  • Loading branch information
GabrielBuica committed May 9, 2024
1 parent 0a3b936 commit a0c84e5
Showing 1 changed file with 1 addition and 19 deletions.
20 changes: 1 addition & 19 deletions ocaml/xapi/storage_mux.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,8 @@ module D = Debug.Make (struct let name = "mux" end)

open D

(* Sets the logging context based on `dbg`.
Also adds a new tracing span, linked to the parent span from `dbg`, if available. *)
let with_dbg ~name ~dbg f =
let open Debug_info in
let di = of_string dbg in
Debug.with_thread_associated di.log
(fun () ->
let name = "SMAPIv2." ^ name in
let tracer = Tracing.get_tracer ~name in
let span = Tracing.Tracer.start ~tracer ~name ~parent:di.tracing () in
match span with
| Ok span_context ->
let result = f {di with tracing= span_context} in
let _ = Tracing.Tracer.finish span_context in
result
| Error e ->
D.warn "Failed to start tracing: %s" (Printexc.to_string e) ;
f di
)
()
Debug_info.with_dbg ~with_thread:true ~module_name:"SMAPIv2" ~name ~dbg f

type processor = Rpc.call -> Rpc.response

Expand Down

0 comments on commit a0c84e5

Please sign in to comment.