Howdy fine people,
Trace is a lightweight library designed for instrumenting library and executable code with a low dependency cost. It provides abstractions for basic logging, traces (spans), and metrics, with a low footprint. The goal is that it’s ok to depend on it in libraries, and it costs almost nothing at runtime in the absence of a collector. The cost of a call in the absence of a collector is basically an atomic load and a comparison to
A collector is a backend that is typically registered at program startup. Only applications should ever specify a backend. There is a simple
trace-tef library that provides a backend that writes into a .json file in the Catapult/TEF format (compatible with
chrome://tracing in chrome, and with perfetto).
Which brings me to tracy-client. It is a library that provides direct bindings to the excellent Tracy project. It also comes with [tracy-client.trace], which provides a Trace backend that forwards events to Tracy over the network (while the program is running). It can be quite useful for interactive programs such as games, but also for CPU-oriented programs in general. The bindings work, but they don’t cover the full extent of Tracy yet (which notably include frames for graphic programs).
So far these are the two released backends for Trace, but I have a Opentelemetry backend in the works; it won’t cover the depth of options of OTEL but it will make it possible to reuse trace-based instrumentation with any OTEL collector. Another exciting possibility with OCaml 5.1 is to use the upcoming
Runtime_events (and custom user events) to forward trace events to an external logger with low overhead.
Docs for Trace can be found here.
Trace is licensed under the MIT license, and tracy-client under BSD-3.