package opentelemetry-client-ocurl

  1. Overview
  2. Docs

Source file common_.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
41
42
module Atomic = Opentelemetry_atomic.Atomic
include Opentelemetry.Lock

let spf = Printf.sprintf

let ( let@ ) = ( @@ )

let tid () = Thread.id @@ Thread.self ()

let debug_ =
  ref
    (match Sys.getenv_opt "OTEL_OCAML_DEBUG" with
    | Some ("1" | "true") -> true
    | _ -> false)

let default_url = "http://localhost:4318"

let url =
  ref (try Sys.getenv "OTEL_EXPORTER_OTLP_ENDPOINT" with _ -> default_url)

let get_url () = !url

let set_url s = url := s

let parse_headers s =
  let parse_header s =
    match String.split_on_char '=' s with
    | [ key; value ] -> key, value
    | _ -> failwith "Unexpected format for header"
  in
  String.split_on_char ',' s |> List.map parse_header

let default_headers = []

let headers =
  ref
    (try parse_headers (Sys.getenv "OTEL_EXPORTER_OTLP_HEADERS")
     with _ -> default_headers)

let get_headers () = !headers

let set_headers s = headers := s
OCaml

Innovation. Community. Security.