mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-08 03:47:59 -04:00
feat client: add Exporter_add_batching
This commit is contained in:
parent
bff2c4bcce
commit
53335468d9
2 changed files with 27 additions and 2 deletions
|
|
@ -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;
|
||||
|
|
|
|||
25
src/client/exporter_add_batching.ml
Normal file
25
src/client/exporter_add_batching.ml
Normal 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 }
|
||||
Loading…
Add table
Reference in a new issue