mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-07 18:37:56 -05:00
helpers to emit in *_provider
This commit is contained in:
parent
14e892454c
commit
fa14ddf1f8
4 changed files with 15 additions and 5 deletions
|
|
@ -42,6 +42,10 @@ let get_logger ?name ?version ?(attrs : (string * [< Value.t ]) list = [])
|
|||
(** A Logger.t that lazily reads the global at emit time *)
|
||||
let default_logger : Logger.t = get_logger ()
|
||||
|
||||
(** Emit log with current logger *)
|
||||
let[@inline] emit (log : Log_record.t) : unit =
|
||||
Emitter.emit (get ()).emit [ log ]
|
||||
|
||||
open Log_record
|
||||
|
||||
(** Create log record and emit it on [logger] *)
|
||||
|
|
|
|||
|
|
@ -39,6 +39,9 @@ let get_meter ?name ?version ?(attrs : (string * [< Value.t ]) list = [])
|
|||
clock = { Clock.now = (fun () -> Clock.now (Clock.Main.get ())) };
|
||||
}
|
||||
|
||||
(** Emit with current meter *)
|
||||
let[@inline] emit (m : Metrics.t) : unit = Emitter.emit (get ()).emit [ m ]
|
||||
|
||||
(** A Meter.t that lazily reads the global at emit time *)
|
||||
let default_meter : Meter.t = get_meter ()
|
||||
|
||||
|
|
|
|||
|
|
@ -41,16 +41,15 @@ let[@inline] active () : Aswitch.t =
|
|||
| None -> Aswitch.dummy
|
||||
| Some exp -> Exporter.active exp
|
||||
|
||||
let add_on_tick_callback (f : unit -> unit) : unit =
|
||||
Globals.add_on_tick_callback f
|
||||
let add_on_tick_callback : (unit -> unit) -> unit = Globals.add_on_tick_callback
|
||||
|
||||
let run_tick_callbacks () : unit = Globals.run_tick_callbacks ()
|
||||
let run_tick_callbacks : unit -> unit = Globals.run_tick_callbacks
|
||||
|
||||
(** Tick all providers and run all registered callbacks. Call this periodically
|
||||
(e.g. every 500ms) to drive metrics collection, GC metrics, and batch
|
||||
timeout flushing. This is the single function client libraries should call
|
||||
from their ticker. *)
|
||||
let tick () : unit = Globals.run_tick_callbacks ()
|
||||
let tick : unit -> unit = Globals.run_tick_callbacks
|
||||
|
||||
let set ?batch_traces ?batch_metrics ?batch_logs
|
||||
?(batch_timeout = Mtime.Span.(2_000 * ms)) (exp : Exporter.t) : unit =
|
||||
|
|
|
|||
|
|
@ -5,10 +5,14 @@ open struct
|
|||
let provider_ : Tracer.t Atomic.t = Atomic.make Tracer.dummy
|
||||
end
|
||||
|
||||
(** Get current tracer. *)
|
||||
let get () : Tracer.t = Atomic.get provider_
|
||||
|
||||
(** Set current tracer *)
|
||||
let set (t : Tracer.t) : unit = Atomic.set provider_ t
|
||||
|
||||
(** Replace current tracer by the dummy one. All spans will be discarded from
|
||||
now on. *)
|
||||
let clear () : unit = Atomic.set provider_ Tracer.dummy
|
||||
|
||||
(** Get a tracer pre-configured with a fixed set of attributes added to every
|
||||
|
|
@ -44,7 +48,7 @@ let get_tracer ?name ?version ?(attrs : (string * [< Value.t ]) list = [])
|
|||
let default_tracer : Tracer.t = get_tracer ()
|
||||
|
||||
(** Emit a span directly via the current global tracer *)
|
||||
let emit (span : Span.t) : unit = Emitter.emit default_tracer.emit [ span ]
|
||||
let[@inline] emit (span : Span.t) : unit = Emitter.emit (get ()).emit [ span ]
|
||||
|
||||
(** Helper to implement {!with_} and similar functions *)
|
||||
let with_thunk_and_finally (self : Tracer.t) ?(force_new_trace_id = false)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue