package opentelemetry

  1. Overview
  2. Docs
Core library for instrumentation and serialization for https://opentelemetry.io

Install

dune-project
 Dependency

Authors

Maintainers

Sources

opentelemetry-0.90.tbz
sha256=c3989bb678f57e5276209d3c60afb29cdca33122288de55e591fbbe2e50a662c
sha512=ba8339256c9b2d8c99c8304991a3047f280a01e492add4cf82bf1d43dfa51e790366c09c6901c0501b8b8e1f810c6e128e33dd33542d785013407f642ade4eea

doc/src/opentelemetry.core/clock.ml.html

Source file clock.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
open Opentelemetry_atomic

type t = { now: unit -> Timestamp_ns.t } [@@unboxed]
(** A clock: can get the current timestamp, with nanoseconds precision *)

let[@inline] now (self : t) : Timestamp_ns.t = self.now ()

open struct
  module TS = Timestamp_ns

  let ns_in_a_day = Int64.(mul 1_000_000_000L (of_int (24 * 3600)))

  (** Current unix timestamp in nanoseconds *)
  let[@inline] now_ptime_ () : TS.t =
    let d, ps = Ptime_clock.now_d_ps () in
    let d = Int64.(mul (of_int d) ns_in_a_day) in
    let ns = Int64.(div ps 1_000L) in
    Int64.(add d ns)
end

(** Clock that uses ptime. *)
let ptime_clock : t = { now = now_ptime_ }

(** Same as [now ptime_clock] *)
let now_ptime = now_ptime_

(** Singleton clock *)
module Main = struct
  open struct
    let main : t Atomic.t = Atomic.make ptime_clock
  end

  let[@inline] get () = Atomic.get main

  (** Set the current clock *)
  let set t : unit = Util_atomic.update_cas main (fun _ -> (), t)
end

(** Timestamp using the main clock *)
let[@inline] now_main () = now (Main.get ())