package trace
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=c173d6bf9433e9eeb41bbddda116a296373d45865841dcbb78bff3be8abd9fd8
sha512=1105c52112095fdc8d4961d7346b02e416627bde6ac79ddd137bff63ac0ff5cd23fa53192be642614efadb9cb0cbb83b7d571bb5a0d100ad0ae6d10bc61d3bba
doc/trace.core/Trace_core/index.html
Module Trace_coreSource
Main tracing interface.
This interface is intended to be lightweight and usable in both libraries and applications. It has very low overhead if no Collector.t is installed.
A span. Its representation is defined by the current collector.
type parent = | P_unknown(*Parent is not specified at this point
*)| P_none(*We know the current span has no parent
*)| P_some of span(*We know the parent of the current span
*)
Information about a span's parent span, if any.
User defined data, generally passed as key/value pairs to whatever collector is installed (if any).
An extension parameter, used to carry information for spans/messages/metrics that can be backend-specific or just not envisioned by trace.
Access/set the current span from some ambient context.
Tracing
Is there a collector?
This is fast, so that the traced program can check it before creating any span or message.
Set level used for spans that do not specify it. The default default value is Level.Trace.
val with_span :
?level:Level.t ->
?__FUNCTION__:string ->
__FILE__:string ->
__LINE__:int ->
?parent:span option ->
?params:extension_parameter list ->
?data:(unit -> (string * user_data) list) ->
string ->
(span -> 'a) ->
'awith_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.
Depending on the collector, this might clash with some forms of cooperative concurrency in which with_span (fun span -> …) might contain a yield point. Effect-based fibers, etc. might not play well with this style of spans on some or all backends. If you use cooperative concurrency, a safer alternative can be enter_span.
val enter_span :
?level:Level.t ->
?__FUNCTION__:string ->
__FILE__:string ->
__LINE__:int ->
?flavor:[ `Sync | `Async ] ->
?parent:span option ->
?params:extension_parameter list ->
?data:(unit -> (string * user_data) list) ->
string ->
spanEnter a span manually. This means the caller is responsible for exiting the span exactly once on every path that exits the current scope. The context must be passed to the exit function as is.
Exit a span manually. Spans must be nested correctly (ie form a stack or tree).
For some collectors, enter_span and exit_span must run on the same thread (e.g. Tracy). For some others, it doesn't matter.
Add structured data to the given active span (see with_span). Behavior is not specified if the span has been exited.
val message :
?level:Level.t ->
?span:span ->
?params:extension_parameter list ->
?data:(unit -> (string * user_data) list) ->
string ->
unitmessage msg logs a message msg (if a collector is installed). Additional metadata can be provided.
val messagef :
?level:Level.t ->
?span:span ->
?params:extension_parameter list ->
?data:(unit -> (string * user_data) list) ->
((('a, Format.formatter, unit, unit) format4 -> 'a) -> unit) ->
unitmessagef (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.
See message for a description of the other arguments.
Give a name to the current thread. This might be used by the collector to display traces in a more informative way.
Uses Core_ext.Extension_set_thread_name since 0.11
Give a name to the current process. This might be used by the collector to display traces in a more informative way.
Uses Core_ext.Extension_set_process_name since 0.11
val metric :
?level:Level.t ->
?params:extension_parameter list ->
?data:(unit -> (string * user_data) list) ->
string ->
metric ->
unitEmit a metric. Metrics are an extensible type, each collector might support a different subset.
val counter_int :
?level:Level.t ->
?params:extension_parameter list ->
?data:(unit -> (string * user_data) list) ->
string ->
int ->
unitEmit a counter of type int via metric. Counters represent the evolution of some quantity over time.
val counter_float :
?level:Level.t ->
?params:extension_parameter list ->
?data:(unit -> (string * user_data) list) ->
string ->
float ->
unitEmit a counter of type float via metric. See counter_int for more details.
Access the current span from some ambient scope, if supported. This is only supported if a Ambient_span_provider has been set up.
with_current_span_set_to span f sets the span as current span, enters f span, and restores the previous current span (if any).
This is only supported if a Ambient_span_provider has been set up, otherwise it is a no-op.
Automatically called by with_span.
Collector
An event collector. See Collector for more details.
Get current level. This is only meaningful if a collector was set up with setup_collector.
Set the current level of tracing. This only has a visible effect if a collector was installed with setup_collector.
shutdown () shutdowns the current collector, if one was installed, and waits for it to terminate before returning.
with_setup_collector c f installs c, calls f(), and shutdowns c once f() is done.
ambient span provider
Install a provider for current_span and with_current_span_set_to. The default provider does nothing (ie current_span () is always None).
Extensions
Extension event
Trigger an extension event, whose meaning depends on the library that defines it. Some collectors will simply ignore it. This does nothing if no collector is setup.
Core extensions
Deprecated
val enter_manual_span :
parent:explicit_span_ctx option ->
?flavor:[ `Sync | `Async ] ->
?level:Level.t ->
?__FUNCTION__:string ->
__FILE__:string ->
__LINE__:int ->
?data:(unit -> (string * user_data) list) ->
string ->
explicit_spanval enter_manual_sub_span :
parent:explicit_span ->
?flavor:[ `Sync | `Async ] ->
?level:Level.t ->
?__FUNCTION__:string ->
__FILE__:string ->
__LINE__:int ->
?data:(unit -> (string * user_data) list) ->
string ->
explicit_spanval enter_manual_toplevel_span :
?flavor:[ `Sync | `Async ] ->
?level:Level.t ->
?__FUNCTION__:string ->
__FILE__:string ->
__LINE__:int ->
?data:(unit -> (string * user_data) list) ->
string ->
explicit_span