From 592814dab847a1916de5cc2f37c8c4651d03ba7d Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Mon, 22 Jul 2024 10:48:15 -0400 Subject: [PATCH 1/2] fix: emit GC metrics even in the absence of custom metrics --- src/client-ocurl/opentelemetry_client_ocurl.ml | 4 +++- src/core/AList.ml | 5 +++++ src/core/AList.mli | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/client-ocurl/opentelemetry_client_ocurl.ml b/src/client-ocurl/opentelemetry_client_ocurl.ml index 68a8d3cb..d935f427 100644 --- a/src/client-ocurl/opentelemetry_client_ocurl.ml +++ b/src/client-ocurl/opentelemetry_client_ocurl.ml @@ -348,7 +348,9 @@ end = struct Queue.clear local_q; if !must_flush_all then ( - if Batch.len batches.metrics > 0 then send_metrics (); + if Batch.len batches.metrics > 0 || not (AList.is_empty gc_metrics) + then + send_metrics (); if Batch.len batches.logs > 0 then send_logs (); if Batch.len batches.traces > 0 then send_traces () ) else ( diff --git a/src/core/AList.ml b/src/core/AList.ml index faec8000..356f2630 100644 --- a/src/core/AList.ml +++ b/src/core/AList.ml @@ -4,6 +4,11 @@ type 'a t = 'a list Atomic.t let make () = Atomic.make [] +let[@inline] is_empty self : bool = + match Atomic.get self with + | [] -> true + | _ :: _ -> false + let get = Atomic.get let add self x = diff --git a/src/core/AList.mli b/src/core/AList.mli index 4799dd6b..832e3c2e 100644 --- a/src/core/AList.mli +++ b/src/core/AList.mli @@ -5,6 +5,8 @@ type 'a t val get : 'a t -> 'a list (** Snapshot *) +val is_empty : _ t -> bool + val make : unit -> 'a t val add : 'a t -> 'a -> unit From 5d5d909c183b6a149cb06d1981d0c003e00bb78c Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Mon, 22 Jul 2024 10:55:51 -0400 Subject: [PATCH 2/2] also handle the non force case --- src/client-ocurl/opentelemetry_client_ocurl.ml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/client-ocurl/opentelemetry_client_ocurl.ml b/src/client-ocurl/opentelemetry_client_ocurl.ml index d935f427..9d858544 100644 --- a/src/client-ocurl/opentelemetry_client_ocurl.ml +++ b/src/client-ocurl/opentelemetry_client_ocurl.ml @@ -289,8 +289,8 @@ end = struct let batch_max_size_ = 200 - let should_send_batch_ ~config ~now (b : _ Batch.t) : bool = - Batch.len b > 0 + let should_send_batch_ ?(side = []) ~config ~now (b : _ Batch.t) : bool = + (Batch.len b > 0 || side != []) && (Batch.len b >= batch_max_size_ || let timeout = Mtime.Span.(config.Config.batch_timeout_ms * ms) in @@ -355,7 +355,10 @@ end = struct if Batch.len batches.traces > 0 then send_traces () ) else ( let now = Mtime_clock.now () in - if should_send_batch_ ~config ~now batches.metrics then + if + should_send_batch_ ~config ~now batches.metrics + ~side:(AList.get gc_metrics) + then send_metrics (); if should_send_batch_ ~config ~now batches.traces then send_traces ();