mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-12 21:46:20 -04:00
client: split opentelemetry-client.sync off of main client library
that's the place for the synchronous primitives.
This commit is contained in:
parent
62cd8c0cd2
commit
e4177c2843
14 changed files with 49 additions and 5 deletions
|
|
@ -7,13 +7,17 @@ open struct
|
||||||
let pp_span out (sp : OTEL.Span.t) =
|
let pp_span out (sp : OTEL.Span.t) =
|
||||||
let open OTEL in
|
let open OTEL in
|
||||||
Format.fprintf out
|
Format.fprintf out
|
||||||
"@[<2>SPAN {@ trace_id: %a@ span_id: %a@ name: %S@ start: %a@ end: %a@]}"
|
"@[<2>SPAN {@ trace_id: %a@ span_id: %a@ name: %S@ start: %a@ end: %a@ \
|
||||||
|
dur: %.6fs@]}"
|
||||||
Trace_id.pp
|
Trace_id.pp
|
||||||
(Trace_id.of_bytes sp.trace_id)
|
(Trace_id.of_bytes sp.trace_id)
|
||||||
Span_id.pp
|
Span_id.pp
|
||||||
(Span_id.of_bytes sp.span_id)
|
(Span_id.of_bytes sp.span_id)
|
||||||
sp.name Timestamp_ns.pp_debug sp.start_time_unix_nano
|
sp.name Timestamp_ns.pp_debug sp.start_time_unix_nano
|
||||||
Timestamp_ns.pp_debug sp.end_time_unix_nano
|
Timestamp_ns.pp_debug sp.end_time_unix_nano
|
||||||
|
((Int64.to_float sp.end_time_unix_nano
|
||||||
|
-. Int64.to_float sp.start_time_unix_nano)
|
||||||
|
/. 1e9)
|
||||||
|
|
||||||
let pp_log out l =
|
let pp_log out l =
|
||||||
Format.fprintf out "@[<2>LOG %a@]" Proto.Logs.pp_log_record l
|
Format.fprintf out "@[<2>LOG %a@]" Proto.Logs.pp_log_record l
|
||||||
|
|
@ -34,7 +38,7 @@ open struct
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
let stdout ?(clock = OTEL.Clock.Main.dynamic_main) () : OTEL.Exporter.t =
|
let stdout ?(clock = OTEL.Clock.ptime_clock) () : OTEL.Exporter.t =
|
||||||
let open Opentelemetry_util in
|
let open Opentelemetry_util in
|
||||||
let out = Format.std_formatter in
|
let out = Format.std_formatter in
|
||||||
let mutex = Mutex.create () in
|
let mutex = Mutex.create () in
|
||||||
|
|
|
||||||
|
|
@ -52,10 +52,12 @@ end = struct
|
||||||
|
|
||||||
let tick (self : state) = Notifier.trigger self.notify
|
let tick (self : state) = Notifier.trigger self.notify
|
||||||
|
|
||||||
(** Shutdown one worker, when the queue is closed *)
|
(** Shutdown worker *)
|
||||||
let shutdown_worker (self : state) : unit =
|
let shutdown_worker (self : state) : unit =
|
||||||
(* we were the last worker *)
|
(* only one worker, so, turn off exporter *)
|
||||||
(* Printf.eprintf "worker %d: last one!\n%!" tid; *)
|
OTEL.Exporter.shutdown self.exp;
|
||||||
|
|
||||||
|
(* and we are shut down! *)
|
||||||
Atomic.set self.status Stopped;
|
Atomic.set self.status Stopped;
|
||||||
Aswitch.turn_off self.active_trigger
|
Aswitch.turn_off self.active_trigger
|
||||||
|
|
||||||
|
|
|
||||||
1
src/client/sync/common_.ml
Normal file
1
src/client/sync/common_.ml
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
module OTEL = Opentelemetry
|
||||||
23
src/client/sync/dune
Normal file
23
src/client/sync/dune
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
(library
|
||||||
|
(name opentelemetry_client_sync)
|
||||||
|
(public_name opentelemetry-client.sync)
|
||||||
|
(flags
|
||||||
|
:standard
|
||||||
|
-open
|
||||||
|
Opentelemetry_util
|
||||||
|
-open
|
||||||
|
Opentelemetry_client
|
||||||
|
-open
|
||||||
|
Opentelemetry_atomic)
|
||||||
|
(libraries
|
||||||
|
opentelemetry.util
|
||||||
|
opentelemetry.atomic
|
||||||
|
opentelemetry.emitter
|
||||||
|
(re_export opentelemetry.core)
|
||||||
|
(re_export opentelemetry)
|
||||||
|
(re_export opentelemetry-client)
|
||||||
|
(re_export threads)
|
||||||
|
mtime
|
||||||
|
mtime.clock.os
|
||||||
|
unix)
|
||||||
|
(synopsis "Synchronous/threading-related helpers for opentelemetry-client"))
|
||||||
14
src/client/sync/shutdown_sync.ml
Normal file
14
src/client/sync/shutdown_sync.ml
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
open Common_
|
||||||
|
|
||||||
|
(** Shutdown this exporter and block the thread until it's done.
|
||||||
|
|
||||||
|
{b NOTE}: this might deadlock if the exporter runs entirely in the current
|
||||||
|
thread! *)
|
||||||
|
let shutdown (exp : OTEL.Exporter.t) : unit =
|
||||||
|
let q = Sync_queue.create () in
|
||||||
|
OTEL.Exporter.on_stop exp (Sync_queue.push q);
|
||||||
|
OTEL.Exporter.shutdown exp;
|
||||||
|
Sync_queue.pop q
|
||||||
|
|
||||||
|
(** Shutdown main exporter and wait *)
|
||||||
|
let shutdown_main () : unit = Option.iter shutdown (OTEL.Main_exporter.get ())
|
||||||
Loading…
Add table
Reference in a new issue