diff --git a/src/client-ocurl/config.ml b/src/client-ocurl/config.ml index 9ae54fc3..fb86c0d2 100644 --- a/src/client-ocurl/config.ml +++ b/src/client-ocurl/config.ml @@ -7,6 +7,7 @@ type t = { batch_timeout_ms: int; bg_threads: int; ticker_thread: bool; + ticker_interval_ms: int; self_trace: bool; } @@ -20,19 +21,20 @@ let pp out self = batch_timeout_ms; bg_threads; ticker_thread; + ticker_interval_ms; self_trace; } = self in Format.fprintf out "{@[ debug=%B;@ url=%S;@ headers=%a;@ batch_timeout_ms=%d; bg_threads=%d;@ \ - ticker_thread=%B;@ self_trace=%B @]}" + ticker_thread=%B;@ ticker_interval_ms=%d;@ self_trace=%B @]}" debug url ppheaders headers batch_timeout_ms bg_threads ticker_thread - self_trace + ticker_interval_ms self_trace let make ?(debug = !debug_) ?(url = get_url ()) ?(headers = get_headers ()) - ?(batch_timeout_ms = 500) ?(bg_threads = 4) ?(ticker_thread = true) - ?(self_trace = true) () : t = + ?(batch_timeout_ms = 2_000) ?(bg_threads = 4) ?(ticker_thread = true) + ?(ticker_interval_ms = 500) ?(self_trace = true) () : t = let bg_threads = max 2 (min bg_threads 32) in { debug; @@ -41,5 +43,6 @@ let make ?(debug = !debug_) ?(url = get_url ()) ?(headers = get_headers ()) batch_timeout_ms; bg_threads; ticker_thread; + ticker_interval_ms; self_trace; } diff --git a/src/client-ocurl/config.mli b/src/client-ocurl/config.mli index 91f6508d..270aa2d2 100644 --- a/src/client-ocurl/config.mli +++ b/src/client-ocurl/config.mli @@ -12,12 +12,18 @@ type t = private { (** Number of milliseconds after which we will emit a batch, even incomplete. Note that the batch might take longer than that, because this is - only checked when a new event occurs. Default 500. *) + only checked when a new event occurs or when a tick + is emitted. Default 2_000. *) bg_threads: int; (** Are there background threads, and how many? Default [4] *) ticker_thread: bool; (** If true, start a thread that regularly checks if signals should be sent to the collector. Default [true] *) + ticker_interval_ms: int; + (** Interval for ticker thread, in milliseconds. This is + only useful if [ticker_thread] is [true]. + Default 500. + @since NEXT_RELEASE *) self_trace: bool; (** If true, the OTEL library will also emit its own spans. @since NEXT_RELEASE *) @@ -34,6 +40,7 @@ val make : ?batch_timeout_ms:int -> ?bg_threads:int -> ?ticker_thread:bool -> + ?ticker_interval_ms:int -> ?self_trace:bool -> unit -> t diff --git a/src/client-ocurl/opentelemetry_client_ocurl.ml b/src/client-ocurl/opentelemetry_client_ocurl.ml index de3fc819..b9b1ba2c 100644 --- a/src/client-ocurl/opentelemetry_client_ocurl.ml +++ b/src/client-ocurl/opentelemetry_client_ocurl.ml @@ -370,14 +370,14 @@ end = struct | Event.E_metric m -> Batch.push batches.metrics m | Event.E_trace tr -> Batch.push batches.traces tr | Event.E_logs logs -> Batch.push batches.logs logs - | Event.E_tick -> () + | Event.E_tick -> + (* the only impact of "tick" is that it wakes us up regularly *) + () | Event.E_flush_all -> must_flush_all := true in - while not (Queue.is_empty local_q) do - let ev = Queue.pop local_q in - process_ev ev - done; + Queue.iter process_ev local_q; + Queue.clear local_q; if !must_flush_all then ( if Batch.len batches.metrics > 0 then send_metrics (); @@ -545,7 +545,8 @@ let setup_ ?(stop = Atomic.make false) ?(config : Config.t = Config.make ()) () Atomic.set Self_trace.enabled config.self_trace; if config.ticker_thread then ( - let sleep_ms = min 5_000 (max 2 config.batch_timeout_ms) in + (* at most a minute *) + let sleep_ms = min 60_000 (max 2 config.ticker_interval_ms) in ignore (setup_ticker_thread ~stop ~sleep_ms backend () : Thread.t) );