mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-08 03:47:59 -04:00
wip: opentelemetry.emitter with same time
a bit like a buffered writer for any data
This commit is contained in:
parent
959cf724fd
commit
08be80b74b
2 changed files with 35 additions and 0 deletions
5
src/emitter/dune
Normal file
5
src/emitter/dune
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
(library
|
||||
(name opentelemetry_emitter)
|
||||
(public_name opentelemetry.emitter)
|
||||
(libraries mtime mtime.clock.os)
|
||||
(synopsis "Modular emitters for a single signal at a time"))
|
||||
30
src/emitter/emitter.ml
Normal file
30
src/emitter/emitter.ml
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
(** Emitters *)
|
||||
|
||||
exception Closed
|
||||
|
||||
type 'a t = {
|
||||
emit: 'a list -> unit;
|
||||
(** Emit signals. @raise Closed if the emitter is closed. *)
|
||||
tick: now:Mtime.t -> unit;
|
||||
(** Call regularly to ensure background work is done *)
|
||||
closed: unit -> bool; (** True if the emitter was closed *)
|
||||
flush_and_close: unit -> unit;
|
||||
(** Flush internal buffered signals, then close *)
|
||||
}
|
||||
(** An emitter for values of type ['a]. *)
|
||||
|
||||
let[@inline] emit (self : _ t) l : unit = if l <> [] then self.emit l
|
||||
|
||||
let[@inline] tick (self : _ t) ~now : unit = self.tick ~now
|
||||
|
||||
let[@inline] closed self : bool = self.closed ()
|
||||
|
||||
let[@inline] flush_and_close (self : _ t) : unit = self.flush_and_close ()
|
||||
|
||||
let map (f : 'a -> 'b) (self : 'b t) : 'a t =
|
||||
{ self with emit = (fun l -> self.emit (List.map f l)) }
|
||||
|
||||
(* TODO: batching, either regular or sharded to reduce contention *)
|
||||
(* TODO: sampling *)
|
||||
|
||||
(* TODO: use in Opentelemetry, and also for Tracer, Logger, etc. *)
|
||||
Loading…
Add table
Reference in a new issue