package trace
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=8927276718e0cc3a991716c30d70742b84e474324372b302d37b0afe5b5ba894
sha512=3e1b71f81edd9262ad97f5c67d06f8b012ddc01a2514eb2e1e4832dae481cbef9d89eb132f236b233dd3a67d3c95051685686b63f2c8e82bcc0bacc2412d5f50
doc/trace.core/Trace_core/index.html
Module Trace_core
Source
Trace.
A span identifier.
The meaning of the identifier depends on the collector.
User defined data, generally passed as key/value pairs to whatever collector is installed (if any).
Tracing
Is there a collector?
This is fast, so that the traced program can check it before creating any span or message
val enter_span :
?__FUNCTION__:string ->
__FILE__:string ->
__LINE__:int ->
?data:(unit -> (string * user_data) list) ->
string ->
span
Enter a span. A span is a delimited period of time with a start instant ("enter") and stop instant ("exit"), associated with some metadata about the code entering/exiting some piece of code.
In particular the entrypoint comes with the location of the code (you can use __FILE__
and __LINE__
directly in OCaml), a mandatory name, and some optional metadata in a JSON-like representation.
Exit the span.
This should be called exactly once per span (even in case of exception). Once this is called, a timestamp might be recorded, and the span is considered finished and can't be used anymore
val with_span :
?__FUNCTION__:string ->
__FILE__:string ->
__LINE__:int ->
?data:(unit -> (string * user_data) list) ->
string ->
(span -> 'a) ->
'a
with_span ~__FILE__ ~__LINE__ name f
enters a new span sp
, and calls f sp
. sp
might be a dummy span if no collector is installed. When f sp
returns or raises, the span sp
is exited.
This is the recommended way to instrument most code.
message msg
logs a message msg
(if a collector is installed). Additional metadata can be provided.
val messagef :
?span:span ->
?data:(unit -> (string * user_data) list) ->
((('a, Format.formatter, unit, unit) format4 -> 'a) -> unit) ->
unit
messagef (fun k->k"hello %s %d!" "world" 42)
is like message "hello world 42!"
but only computes the string formatting if a collector is installed.
Give a name to the current thread. This might be used by the collector to display traces in a more informative way.
Give a name to the current process. This might be used by the collector to display traces in a more informative way.
Emit a counter of type int
. Counters represent the evolution of some quantity over time.
Emit a counter of type float
. See counter_int
for more details.
Collector
An event collector.
See Collector
for more details.
shutdown ()
shutdowns the current collector, if one was installed, and waits for it to terminate before returning.