ocaml-probe#
ocaml-probe is a typed facade over OCaml runtime_events user events.
Libraries declare event and span values with flat scalar fields, then emit them
to the runtime event ring. A descriptor event is written before the first data
event for each declaration and re-emitted at regular intervals, so consumers
can discover names, docs and field types from the stream even when they attach
to an already-running process. Probe.Consumer.decode turns packets back into
typed records; string values clipped to fit the 1024-byte packet limit decode
as Truncated. Span context is domain-local by default; Eio applications call
Probe_eio.install () (from ocaml-probe.eio) once to make it fiber-local.
type fetch = { url : string; status : int }
let fetch =
Probe.event "oci.blob.fetch"
Probe.Fields.(
obj (fun url status -> { url; status })
|> field "url" string ~enc:(fun t -> t.url)
|> field "status" int ~enc:(fun t -> t.status)
|> seal)
let () = Probe.emit fetch { url = "https://example.invalid/layer"; status = 200 }
Installation#
Install with opam:
$ opam install probe
If opam cannot find the package, it may not yet be released in the public
opam-repository. Add the overlay repository, then install it:
$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install probe
Codec events#
Protocol stacks that expose encode/decode probes can use Probe.Event.v to get
a standard set of event, byte-count and span helpers.
type operation = Encode | Decode
let to_string = function Encode -> "encode" | Decode -> "decode"
module Event = (val Probe.Event.v "foo.codec" ~doc:"Foo codec operations" to_string)
let () = Event.emit_probe ~operation:Encode ~bytes:42 ~ok:true