make add_event lazy

This commit is contained in:
Simon Cruanes 2022-03-21 11:19:36 -04:00
parent 64d9a91d51
commit 341c70f18f
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4

View file

@ -96,6 +96,9 @@ module Collector = struct
let backend : backend option ref = ref None let backend : backend option ref = ref None
(** Is there a configured backend? *)
let[@inline] has_backend () : bool = !backend != None
let send_trace (l:Trace.resource_spans list) ~over ~ret = let send_trace (l:Trace.resource_spans list) ~over ~ret =
match !backend with match !backend with
| None -> over(); ret() | None -> over(); ret()
@ -393,9 +396,14 @@ module Trace = struct
mutable events: Event.t list; mutable events: Event.t list;
} }
(** Add an event to the scope. It will be aggregated into the span *) (** Add an event to the scope. It will be aggregated into the span.
let[@inline] add_event (scope:scope) (ev:Event.t) : unit =
scope.events <- ev :: scope.events Note that this takes a function that produces an event, and will only
call it if there is an instrumentation backend. *)
let[@inline] add_event (scope:scope) (ev:unit -> Event.t) : unit =
if Collector.has_backend() then (
scope.events <- ev() :: scope.events
)
(** Sync span guard *) (** Sync span guard *)
let with_ let with_