From 274496fe81ead82be41db91baa65cd6637a7219e Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Fri, 15 Sep 2023 13:00:47 -0400 Subject: [PATCH] add `?parent` to `with_span_lwt` --- src/lwt/trace_lwt.ml | 19 ++++++++++++------- src/lwt/trace_lwt.mli | 3 ++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/lwt/trace_lwt.ml b/src/lwt/trace_lwt.ml index a349635..00aee11 100644 --- a/src/lwt/trace_lwt.ml +++ b/src/lwt/trace_lwt.ml @@ -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 diff --git a/src/lwt/trace_lwt.mli b/src/lwt/trace_lwt.mli index 1c8d606..611256e 100644 --- a/src/lwt/trace_lwt.mli +++ b/src/lwt/trace_lwt.mli @@ -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 *)