Typed runtime_events probes for OCaml
0

Configure Feed

Select the types of activity you want to include in your feed.

OCaml 93.1%
C 1.5%
JavaScript 0.8%
Dune 0.6%
WebAssembly 0.5%
Other 3.4%
41 1 0

Clone this repository

https://git.vm.fail/gazagnaire.org/ocaml-probe https://git.vm.fail/did:plc:yp5ewqof7x2otakp7j4qhbvn
ssh://git@git.recoil.org:2222/gazagnaire.org/ocaml-probe ssh://git@git.recoil.org:2222/did:plc:yp5ewqof7x2otakp7j4qhbvn

For self-hosted knots, clone URLs may differ based on your setup.


README.md

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