update the emit test so it records how many bytes were emitted

This commit is contained in:
Simon Cruanes 2025-10-30 16:48:04 -04:00
parent bf09b58a63
commit f000c11406
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
4 changed files with 17 additions and 2 deletions

View file

@ -117,6 +117,8 @@ module Backend_impl : sig
val send_event : t -> Event.t -> unit
val n_bytes_sent : unit -> int
val shutdown : t -> on_done:(unit -> unit) -> unit
end = struct
open Opentelemetry.Proto
@ -187,6 +189,10 @@ end = struct
let[@inline] send_event (self : t) ev : unit = B_queue.push self.q ev
let n_bytes_sent_ = Atomic.make 0
let[@inline] n_bytes_sent () = Atomic.get n_bytes_sent_
(** Thread that, in a loop, reads from [q] to get the next message to send via
http *)
let bg_thread_loop (self : t) : unit =
@ -199,7 +205,9 @@ end = struct
Self_trace.with_ ~kind:Span_kind_producer name
~attrs:[ "n", `Int (List.length l) ]
in
conv l |> send_http_ ~stop ~config ~url client
let msg = conv l in
ignore (Atomic.fetch_and_add n_bytes_sent_ (String.length msg) : int);
send_http_ ~stop ~config ~url client msg
in
try
while not (Atomic.get stop) do
@ -471,3 +479,5 @@ let with_setup ?stop ?config ?(enable = true) () f =
Fun.protect ~finally:remove_backend f
) else
f ()
let n_bytes_sent = Backend_impl.n_bytes_sent

View file

@ -11,6 +11,9 @@ val set_headers : (string * string) list -> unit
module Atomic = Opentelemetry_atomic.Atomic
module Config = Config
val n_bytes_sent : unit -> int
(** Global counter of bytes sent (or attempted to be sent) *)
val create_backend :
?stop:bool Atomic.t ->
?config:Config.t ->

View file

@ -1,6 +1,6 @@
module OT = Opentelemetry
let enabled = Atomic.make true
let enabled = Atomic.make false
let add_event (scope : OT.Scope.t) ev = OT.Scope.add_event scope (fun () -> ev)

View file

@ -86,6 +86,8 @@ let run () =
[
sum ~name:"num-sleep" ~is_monotonic:true
[ int (Atomic.get num_sleep) ];
sum ~name:"otel.bytes-sent" ~is_monotonic:true ~unit_:"B"
[ int (Opentelemetry_client_ocurl.n_bytes_sent ()) ];
]);
let n_jobs = max 1 !n_jobs in