feat: opentelemetry.domain shim

This commit is contained in:
Simon Cruanes 2025-12-01 21:21:57 -05:00
parent abe022dbc0
commit f55775a55c
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
3 changed files with 44 additions and 0 deletions

14
src/domain/dune Normal file
View file

@ -0,0 +1,14 @@
(library
(name opentelemetry_domain)
(synopsis "Compatibility package for the Domain module for opentelemetry")
(public_name opentelemetry.domain)
(modules opentelemetry_domain))
(executable
(modules gen)
(name gen))
(rule
(targets opentelemetry_domain.ml)
(action
(run ./gen.exe)))

26
src/domain/gen.ml Normal file
View file

@ -0,0 +1,26 @@
let domain_4 =
{|
let cpu_relax = ignore
let relax_loop : int -> unit = ignore
|}
let domain_5 =
{|
let cpu_relax = Domain.cpu_relax
let relax_loop i =
for _j = 1 to i do cpu_relax () done
|}
let write_file file s =
let oc = open_out file in
output_string oc s;
close_out oc
let () =
let version = Scanf.sscanf Sys.ocaml_version "%d.%d.%s" (fun x y _ -> x, y) in
write_file "opentelemetry_domain.ml"
(if version >= (5, 0) then
domain_5
else
domain_4);
()

View file

@ -0,0 +1,4 @@
val cpu_relax : unit -> unit
val relax_loop : int -> unit
(** Call {!cpu_relax} n times *)