wip: refactor

This commit is contained in:
Simon Cruanes 2025-12-03 16:07:14 -05:00
parent f0cd1ad375
commit d52345c3a8
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
3 changed files with 18 additions and 15 deletions

View file

@ -216,7 +216,7 @@ module type EMITTER = sig
val push_logs : Logs.resource_logs list -> unit val push_logs : Logs.resource_logs list -> unit
val set_on_tick_callbacks : (unit -> unit) AList.t -> unit val set_on_tick_callbacks : (unit -> unit) Alist.t -> unit
val tick : unit -> unit val tick : unit -> unit
@ -312,7 +312,7 @@ let mk_emitter ~stop ~net (config : Config.t) : (module EMITTER) =
Fiber.fork ~sw @@ emit_metrics_maybe ~now ~force; Fiber.fork ~sw @@ emit_metrics_maybe ~now ~force;
Fiber.fork ~sw @@ emit_traces_maybe ~now ~force Fiber.fork ~sw @@ emit_traces_maybe ~now ~force
let on_tick_cbs_ = Atomic.make (AList.make ()) let on_tick_cbs_ = Atomic.make (Alist.make ())
let run_tick_callbacks () = let run_tick_callbacks () =
List.iter List.iter
@ -321,7 +321,7 @@ let mk_emitter ~stop ~net (config : Config.t) : (module EMITTER) =
with e -> with e ->
Printf.eprintf "on tick callback raised: %s\n" Printf.eprintf "on tick callback raised: %s\n"
(Printexc.to_string e)) (Printexc.to_string e))
(AList.get @@ Atomic.get on_tick_cbs_) (Alist.get @@ Atomic.get on_tick_cbs_)
end in end in
let module M = struct let module M = struct
let set_on_tick_callbacks = Atomic.set on_tick_cbs_ let set_on_tick_callbacks = Atomic.set on_tick_cbs_

View file

@ -187,7 +187,7 @@ module type EMITTER = sig
val push_logs : Logs.resource_logs list -> unit val push_logs : Logs.resource_logs list -> unit
val set_on_tick_callbacks : (unit -> unit) AList.t -> unit val set_on_tick_callbacks : (unit -> unit) Alist.t -> unit
val tick : unit -> unit val tick : unit -> unit
@ -218,7 +218,7 @@ let mk_emitter ~stop ~(config : Config.t) () : (module EMITTER) =
let batch_logs : Logs.resource_logs Batch.t = let batch_logs : Logs.resource_logs Batch.t =
Batch.make ?batch:config.batch_logs ?timeout () Batch.make ?batch:config.batch_logs ?timeout ()
let on_tick_cbs_ = Atomic.make (AList.make ()) let on_tick_cbs_ = Atomic.make (Alist.make ())
let set_on_tick_callbacks = Atomic.set on_tick_cbs_ let set_on_tick_callbacks = Atomic.set on_tick_cbs_
@ -348,7 +348,7 @@ let mk_emitter ~stop ~(config : Config.t) () : (module EMITTER) =
with e -> with e ->
Printf.eprintf "on tick callback raised: %s\n" Printf.eprintf "on tick callback raised: %s\n"
(Printexc.to_string e)) (Printexc.to_string e))
(AList.get @@ Atomic.get on_tick_cbs_); (Alist.get @@ Atomic.get on_tick_cbs_);
let now = Mtime_clock.now () in let now = Mtime_clock.now () in
let+ (_ : bool) = emit_traces_maybe ~now httpc let+ (_ : bool) = emit_traces_maybe ~now httpc
and+ (_ : bool) = emit_logs_maybe ~now httpc and+ (_ : bool) = emit_logs_maybe ~now httpc

View file

@ -7,24 +7,24 @@ module Span = Span
module Span_link = Span_link module Span_link = Span_link
module Globals = Globals module Globals = Globals
module Timestamp_ns = Timestamp_ns module Timestamp_ns = Timestamp_ns
module GC_metrics = GC_metrics module Gc_metrics = Gc_metrics
module Metrics_callbacks = Metrics_callbacks module Metrics_callbacks = Metrics_callbacks
module Trace_context = Trace_context module Trace_context = Trace_context
module GC_metrics = Gc_metrics [@@depecated "use Gc_metrics"]
external reraise : exn -> 'a = "%reraise" external reraise : exn -> 'a = "%reraise"
(** This is equivalent to [Lwt.reraise]. We inline it here so we don't force to (** This is equivalent to [Lwt.reraise]. We inline it here so we don't force to
use Lwt's latest version *) use Lwt's latest version *)
module Trace = struct module Tracer = struct
include Trace include Tracer
(** Sync span guard *) (** Sync span guard *)
let with_ ?force_new_trace_id ?trace_state ?service_name ?attrs ?kind let with_ ?force_new_trace_id ?trace_state ?attrs ?kind ?trace_id ?parent
?trace_id ?parent ?scope ?links name (cb : Scope.t -> 'a Lwt.t) : 'a Lwt.t ?scope ?links name (cb : Scope.t -> 'a Lwt.t) : 'a Lwt.t =
=
let thunk, finally = let thunk, finally =
with_' ?force_new_trace_id ?trace_state ?service_name ?attrs ?kind with_' ?force_new_trace_id ?trace_state ?attrs ?kind ?trace_id ?parent
?trace_id ?parent ?scope ?links name cb ?scope ?links name cb
in in
try%lwt try%lwt
@ -37,11 +37,14 @@ module Trace = struct
reraise e reraise e
end end
module Trace = Tracer [@@deprecated "use Tracer"]
module Metrics = struct module Metrics = struct
include Metrics include Metrics
end end
module Logs = struct module Logs = struct
include Proto.Logs include Proto.Logs
include Logs include Log_record
include Logger
end end