diff --git a/src/client/client_config.mli b/src/client/client_config.mli index b8d0238f..8af6a844 100644 --- a/src/client/client_config.mli +++ b/src/client/client_config.mli @@ -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; diff --git a/src/client/exporter_add_batching.ml b/src/client/exporter_add_batching.ml new file mode 100644 index 00000000..0858d5b8 --- /dev/null +++ b/src/client/exporter_add_batching.ml @@ -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 }