diff --git a/src/core/collector.ml b/src/core/collector.ml index fb7ebbb..180933b 100644 --- a/src/core/collector.ml +++ b/src/core/collector.ml @@ -53,10 +53,15 @@ module type S = sig (** Exit an explicit span. @since 0.3 *) - val add_data_to_span : span -> (string * user_data) list -> unit - (** @since Adds data to the given span. + val add_data : (string * user_data) list -> unit + (** @since Adds data to the ambient span. NEXT_RELEASE *) + val add_data_to_manual_span : + explicit_span -> (string * user_data) list -> unit + (** Adds data to the given span. + @since NEXT_RELEASE *) + val message : ?span:span -> data:(string * user_data) list -> string -> unit (** Emit a message with associated metadata. *) diff --git a/src/core/trace_core.ml b/src/core/trace_core.ml index 2365e8d..d89ed8c 100644 --- a/src/core/trace_core.ml +++ b/src/core/trace_core.ml @@ -55,15 +55,19 @@ let[@inline] exit_manual_span espan : unit = | None -> () | Some (module C) -> C.exit_manual_span espan -let[@inline] add_data_to_span (span : span) data : unit = +let[@inline] add_data data : unit = if data <> [] then ( match A.get collector with | None -> () - | Some (module C) -> C.add_data_to_span span data + | Some (module C) -> C.add_data data ) -let[@inline] add_data_to_explicit_span esp data : unit = - add_data_to_span esp.span data +let[@inline] add_data_to_manual_span esp data : unit = + if data <> [] then ( + match A.get collector with + | None -> () + | Some (module C) -> C.add_data_to_manual_span esp data + ) let message_collector_ (module C : Collector.S) ?span ?(data = fun () -> []) msg : unit = diff --git a/src/core/trace_core.mli b/src/core/trace_core.mli index 1421a08..ee27b6f 100644 --- a/src/core/trace_core.mli +++ b/src/core/trace_core.mli @@ -34,8 +34,9 @@ val with_span : see {!enter_manual_span}. *) -val add_data_to_span : span -> (string * user_data) list -> unit -(** Add structured data to the given span. +val add_data : (string * user_data) list -> unit +(** Add structured data to the current span (the ambient {!with_span}). + Behavior is not specified if there is no current span. @since NEXT_RELEASE *) val enter_manual_sub_span : @@ -79,10 +80,9 @@ val exit_manual_span : explicit_span -> unit {!enter_manual_toplevel_span}. @since 0.3 *) -val add_data_to_explicit_span : - explicit_span -> (string * user_data) list -> unit -(** [add_data_explicit esp data] is [add_data_to_span esp.span data], ie. it adds - the pairs [k:v] from [data] to the span inside [esp]. +val add_data_to_manual_span : explicit_span -> (string * user_data) list -> unit +(** [add_data_explicit esp data] adds [data] to the span [esp]. + The behavior is not specified is the span has been exited already. @since NEXT_RELEASE *) val message :