From c442f3b818c029ed57fcff3d19329e27373ae2bc Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Wed, 4 Mar 2026 13:16:19 -0500 Subject: [PATCH] batch: update n_dropped correctly; also self_debug in Emitter_batch --- src/lib/batch.ml | 3 ++- src/lib/emitter_batch.ml | 15 +++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/lib/batch.ml b/src/lib/batch.ml index b791b926..aa093864 100644 --- a/src/lib/batch.ml +++ b/src/lib/batch.ml @@ -124,7 +124,8 @@ let push (self : _ t) elems : [ `Dropped | `Ok ] = ) in (match res with - | `Dropped -> Atomic.incr self.n_dropped + | `Dropped -> + ignore (Atomic.fetch_and_add self.n_dropped (List.length elems) : int) | `Ok -> ()); res ) diff --git a/src/lib/emitter_batch.ml b/src/lib/emitter_batch.ml index 6c8d0f36..a1c282a3 100644 --- a/src/lib/emitter_batch.ml +++ b/src/lib/emitter_batch.ml @@ -52,12 +52,15 @@ let wrap_emitter_with_batch (self : _ Batch.t) (e : _ Emitter.t) : _ Emitter.t = let emit l = if l <> [] && not (Atomic.get closed_here) then ( - (* Printf.eprintf "otel.batch.add %d items\n%!" (List.length l); *) - Batch.push' self l; - - (* we only check for size here, not for timeout. The [tick] function is - enough for timeouts, whereas [emit] is in the hot path of every single - span/metric/log *) + let old_n_dropped = Batch.n_dropped self in + (match Batch.push self l with + | `Ok -> () + | `Dropped -> + let n_dropped = Batch.n_dropped self in + if n_dropped / 100_000 <> old_n_dropped / 100_000 then + Self_debug.log Debug (fun () -> + Printf.sprintf "otel: batch %s dropped %d items in total" + signal_name n_dropped)); maybe_emit_ self ~e ~mtime:Batch.Internal_.mtime_dummy_ ) in