Skip to content

Commit

Permalink
more helpers in client/sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
c-cube committed Sep 14, 2023
1 parent 29812d0 commit a588ddc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/client/catapult_client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ let default_endpoint = Endpoint_address.default
let with_conn = Connection.with_
let backend_of_conn : Connection.t -> Catapult.backend = Backend.make

(** Parse a remote address. *)
let addr_of_string_exn : string -> Endpoint_address.t =
Endpoint_address.of_string_exn

(** Obtain a trace collector from a network connection *)
let trace_collector_of_conn : Connection.t -> Trace_core.collector =
fun conn -> backend_of_conn conn |> Catapult.trace_collector_of_backend

(** [with_ ~addr () f] runs [f()] in an environment where a connection
to [addr] has been established and is used to forward
tracing events to the remote daemon. *)
let with_ ~addr ?trace_id () (f : unit -> 'a) : 'a =
Connection.with_ ~addr ?trace_id () @@ fun conn ->
Trace_core.setup_collector (trace_collector_of_conn conn);
f ()
8 changes: 8 additions & 0 deletions src/sqlite/catapult_sqlite.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ let backend_of_writer : Writer.t -> Catapult.backend = Backend.make
(** Turn a writer into a Trace collector. *)
let trace_collector_of_writer : Writer.t -> Trace_core.collector =
fun wr -> backend_of_writer wr |> Catapult.trace_collector_of_backend

(** [with_ () f] runs [f()] in a scope where a connection to
a Sqlite DB has been established and is used to store
tracing events emitted from within [f ()]. *)
let with_ ?sync ?append ?file ?trace_id ?dir () (f : unit -> 'a) : 'a =
Writer.with_ ?sync ?append ?file ?trace_id ?dir () @@ fun wr ->
Trace_core.setup_collector (trace_collector_of_writer wr);
f ()

0 comments on commit a588ddc

Please sign in to comment.