From a33c57a46e808a1192a090a6588cdf1f3c3bc129 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Wed, 3 Dec 2025 16:07:14 -0500 Subject: [PATCH] wip: refactor --- .../opentelemetry_client_cohttp_eio.ml | 6 +++--- .../opentelemetry_client_cohttp_lwt.ml | 6 +++--- src/lwt/opentelemetry_lwt.ml | 21 +++++++++++-------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/client-cohttp-eio/opentelemetry_client_cohttp_eio.ml b/src/client-cohttp-eio/opentelemetry_client_cohttp_eio.ml index 9f71d52f..67b7b169 100644 --- a/src/client-cohttp-eio/opentelemetry_client_cohttp_eio.ml +++ b/src/client-cohttp-eio/opentelemetry_client_cohttp_eio.ml @@ -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_ diff --git a/src/client-cohttp-lwt/opentelemetry_client_cohttp_lwt.ml b/src/client-cohttp-lwt/opentelemetry_client_cohttp_lwt.ml index 53786ed2..0f823fbc 100644 --- a/src/client-cohttp-lwt/opentelemetry_client_cohttp_lwt.ml +++ b/src/client-cohttp-lwt/opentelemetry_client_cohttp_lwt.ml @@ -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 diff --git a/src/lwt/opentelemetry_lwt.ml b/src/lwt/opentelemetry_lwt.ml index 7b443c20..2f3cfe02 100644 --- a/src/lwt/opentelemetry_lwt.ml +++ b/src/lwt/opentelemetry_lwt.ml @@ -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