feat client: add Exporter_add_batching

This commit is contained in:
Simon Cruanes 2025-12-05 09:25:03 -05:00
parent bff2c4bcce
commit 53335468d9
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 27 additions and 2 deletions

View file

@ -19,8 +19,8 @@ type t = private {
(** Batch metrics? If [Some i], then this produces batches of (at most)
[i] items. If [None], there is no batching.
Note that traces and metrics are batched separately. Default [None].
*)
Note that traces and metrics are batched separately. Default
[Some 20]. *)
batch_logs: int option;
(** Batch logs? See {!batch_metrics} for details. Default [Some 400] *)
batch_timeout_ms: int;

View file

@ -0,0 +1,25 @@
(** Add batching to emitter based on client config *)
open Common_
open struct
let add_batch ~timeout batch (emitter : 'a OTEL.Emitter.t) : 'a OTEL.Emitter.t
=
let b = Batch.make ~batch ~timeout () in
Batch.wrap_emitter b emitter
end
let add_batching ~(config : Client_config.t) (exp : OTEL.Exporter.t) :
OTEL.Exporter.t =
let timeout = Mtime.Span.(config.batch_timeout_ms * ms) in
let add_batch_opt (b : int option) e =
match b with
| None -> e
| Some b -> add_batch ~timeout b e
in
let emit_spans = add_batch_opt config.batch_traces exp.emit_spans in
let emit_metrics = add_batch_opt config.batch_metrics exp.emit_metrics in
let emit_logs = add_batch_opt config.batch_logs exp.emit_logs in
{ exp with emit_spans; emit_metrics; emit_logs }