make add_data implicit (no span argument)

This commit is contained in:
Simon Cruanes 2023-08-29 22:33:11 -04:00
parent 83baf45207
commit 4137985d69
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
3 changed files with 21 additions and 12 deletions

View file

@ -53,10 +53,15 @@ module type S = sig
(** Exit an explicit span. (** Exit an explicit span.
@since 0.3 *) @since 0.3 *)
val add_data_to_span : span -> (string * user_data) list -> unit val add_data : (string * user_data) list -> unit
(** @since Adds data to the given span. (** @since Adds data to the ambient span.
NEXT_RELEASE *) 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 val message : ?span:span -> data:(string * user_data) list -> string -> unit
(** Emit a message with associated metadata. *) (** Emit a message with associated metadata. *)

View file

@ -55,15 +55,19 @@ let[@inline] exit_manual_span espan : unit =
| None -> () | None -> ()
| Some (module C) -> C.exit_manual_span espan | 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 ( if data <> [] then (
match A.get collector with match A.get collector with
| None -> () | 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 = let[@inline] add_data_to_manual_span esp data : unit =
add_data_to_span esp.span data 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 let message_collector_ (module C : Collector.S) ?span ?(data = fun () -> []) msg
: unit = : unit =

View file

@ -34,8 +34,9 @@ val with_span :
see {!enter_manual_span}. see {!enter_manual_span}.
*) *)
val add_data_to_span : span -> (string * user_data) list -> unit val add_data : (string * user_data) list -> unit
(** Add structured data to the given span. (** Add structured data to the current span (the ambient {!with_span}).
Behavior is not specified if there is no current span.
@since NEXT_RELEASE *) @since NEXT_RELEASE *)
val enter_manual_sub_span : val enter_manual_sub_span :
@ -79,10 +80,9 @@ val exit_manual_span : explicit_span -> unit
{!enter_manual_toplevel_span}. {!enter_manual_toplevel_span}.
@since 0.3 *) @since 0.3 *)
val add_data_to_explicit_span : val add_data_to_manual_span : explicit_span -> (string * user_data) list -> unit
explicit_span -> (string * user_data) list -> unit (** [add_data_explicit esp data] adds [data] to the span [esp].
(** [add_data_explicit esp data] is [add_data_to_span esp.span data], ie. it adds The behavior is not specified is the span has been exited already.
the pairs [k:v] from [data] to the span inside [esp].
@since NEXT_RELEASE *) @since NEXT_RELEASE *)
val message : val message :