add ?parent to with_span_lwt

This commit is contained in:
Simon Cruanes 2023-09-15 13:00:47 -04:00
parent e6f01f57ac
commit 274496fe81
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 14 additions and 8 deletions

View file

@ -2,9 +2,14 @@ include Trace_core
let k_parent : explicit_span Lwt.key = Lwt.new_key ()
let[@inline never] with_span_lwt_real_ ?(force_toplevel = false) ?__FUNCTION__
~__FILE__ ~__LINE__ ?data name f =
let parent = Lwt.get k_parent in
let[@inline never] with_span_lwt_real_ ?parent ?(force_toplevel = false)
?__FUNCTION__ ~__FILE__ ~__LINE__ ?data name f =
let parent =
match parent with
| Some _ as p -> p
| None -> Lwt.get k_parent
in
let espan =
match parent, force_toplevel with
| _, true | None, _ ->
@ -21,10 +26,10 @@ let[@inline never] with_span_lwt_real_ ?(force_toplevel = false) ?__FUNCTION__
fut)
let[@inline] with_span_lwt ?force_toplevel ?__FUNCTION__ ~__FILE__ ~__LINE__
?data name f : _ Lwt.t =
let[@inline] with_span_lwt ?parent ?force_toplevel ?__FUNCTION__ ~__FILE__
~__LINE__ ?data name f : _ Lwt.t =
if enabled () then
with_span_lwt_real_ ?force_toplevel ?__FUNCTION__ ~__FILE__ ~__LINE__ ?data
name f
with_span_lwt_real_ ?parent ?force_toplevel ?__FUNCTION__ ~__FILE__
~__LINE__ ?data name f
else
f 0L

View file

@ -1,4 +1,3 @@
(** Wrapper for tracing with Lwt.
@since NEXT_RELEASE. *)
@ -6,6 +5,7 @@
include module type of Trace_core
val with_span_lwt :
?parent:explicit_span ->
?force_toplevel:bool ->
?__FUNCTION__:string ->
__FILE__:string ->
@ -22,5 +22,6 @@ val with_span_lwt :
@param force_toplevel if true, this span will not have a parent even if
there is one in the implicit context; ie it create a new
{!Trace_core.enter_manual_toplevel_span} in any case.
@param parent an explicit parent, which bypasses the implicit context.
@since NEXT_RELEASE *)