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/span_id.ml.html

Source file span_id.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
type t = bytes

let[@inline] to_bytes self = self

let dummy : t = Bytes.make 8 '\x00'

let create () : t =
  let b = Rand_bytes.rand_bytes_8 () in
  assert (Bytes.length b = 8);
  (* make sure the identifier is not all 0, which is a dummy identifier. *)
  Bytes.set b 0 (Char.unsafe_chr (Char.code (Bytes.get b 0) lor 1));
  b

(* dark magic, woo. We have an [assert] below to do the bound checks once *)
external unsafe_b_get64 : bytes -> int -> int64 = "%caml_bytes_get64u"

let[@inline] is_zero (self : t) : bool =
  (* try to reduce branches *)
  assert (Bytes.length self = 8);
  let n1 = unsafe_b_get64 self 0 in
  n1 = 0L

let[@inline] is_valid self = not (is_zero self)

let[@inline] of_bytes b =
  if Bytes.length b = 8 then
    b
  else
    invalid_arg "span IDs must be 8 bytes in length"

let to_hex = Util_bytes_.bytes_to_hex

let to_hex_into = Util_bytes_.bytes_to_hex_into

let[@inline] of_hex s = of_bytes (Util_bytes_.bytes_of_hex s)

let[@inline] of_hex_substring s off =
  of_bytes (Util_bytes_.bytes_of_hex_substring s off 16)

let pp fmt t = Format.fprintf fmt "%s" (to_hex t)