wip: refactor

This commit is contained in:
Simon Cruanes 2025-12-03 16:07:14 -05:00
parent b433a11c9a
commit a33c57a46e
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 set_on_tick_callbacks : (unit -> unit) AList.t -> unit
val set_on_tick_callbacks : (unit -> unit) Alist.t -> 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_traces_maybe ~now ~force
let on_tick_cbs_ = Atomic.make (AList.make ())
let on_tick_cbs_ = Atomic.make (Alist.make ())
let run_tick_callbacks () =
List.iter
@ -321,7 +321,7 @@ let mk_emitter ~stop ~net (config : Config.t) : (module EMITTER) =
with e ->
Printf.eprintf "on tick callback raised: %s\n"
(Printexc.to_string e))
(AList.get @@ Atomic.get on_tick_cbs_)
(Alist.get @@ Atomic.get on_tick_cbs_)
end in
let module M = struct
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 set_on_tick_callbacks : (unit -> unit) AList.t -> unit
val set_on_tick_callbacks : (unit -> unit) Alist.t -> 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 =
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_
@ -348,7 +348,7 @@ let mk_emitter ~stop ~(config : Config.t) () : (module EMITTER) =
with e ->
Printf.eprintf "on tick callback raised: %s\n"
(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+ (_ : bool) = emit_traces_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 Globals = Globals
module Timestamp_ns = Timestamp_ns
module GC_metrics = GC_metrics
module Gc_metrics = Gc_metrics
module Metrics_callbacks = Metrics_callbacks
module Trace_context = Trace_context
module GC_metrics = Gc_metrics [@@depecated "use Gc_metrics"]
external reraise : exn -> 'a = "%reraise"
(** This is equivalent to [Lwt.reraise]. We inline it here so we don't force to
use Lwt's latest version *)
module Trace = struct
include Trace
module Tracer = struct
include Tracer
(** Sync span guard *)
let with_ ?force_new_trace_id ?trace_state ?service_name ?attrs ?kind
?trace_id ?parent ?scope ?links name (cb : Scope.t -> 'a Lwt.t) : 'a Lwt.t
=
let with_ ?force_new_trace_id ?trace_state ?attrs ?kind ?trace_id ?parent
?scope ?links name (cb : Scope.t -> 'a Lwt.t) : 'a Lwt.t =
let thunk, finally =
with_' ?force_new_trace_id ?trace_state ?service_name ?attrs ?kind
?trace_id ?parent ?scope ?links name cb
with_' ?force_new_trace_id ?trace_state ?attrs ?kind ?trace_id ?parent
?scope ?links name cb
in
try%lwt
@ -37,11 +37,14 @@ module Trace = struct
reraise e
end
module Trace = Tracer [@@deprecated "use Tracer"]
module Metrics = struct
include Metrics
end
module Logs = struct
include Proto.Logs
include Logs
include Log_record
include Logger
end