feat: update and fix opentelemetry.trace

This commit is contained in:
Simon Cruanes 2024-09-30 12:34:16 -04:00
parent 9680d61a36
commit 60a0b843e6
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
3 changed files with 11 additions and 6 deletions

View file

@ -3,4 +3,4 @@
(public_name opentelemetry.trace)
(synopsis "Use opentelemetry as a collector for trace")
(optional)
(libraries ambient-context ambient-context.tls trace.core opentelemetry))
(libraries opentelemetry.ambient-context trace.core opentelemetry))

View file

@ -1,6 +1,6 @@
module Otel = Opentelemetry
module Otrace = Trace_core (* ocaml-trace *)
module TLS = Ambient_context_tls.TLS
module TLS = Thread_local_storage
open struct
let spf = Printf.sprintf
@ -75,9 +75,14 @@ module Internal = struct
let create () : t = { tbl = Active_span_tbl.create 32 }
let tls : t TLS.t = TLS.create ()
let k_tls : t TLS.t = TLS.create ()
let[@inline] get () : t = TLS.get_or_create tls ~create
let[@inline] get () : t =
try TLS.get_exn k_tls
with TLS.Not_set ->
let self = create () in
TLS.set k_tls self;
self
end
let otrace_of_otel (id : Otel.Span_id.t) : int64 =

View file

@ -1,6 +1,6 @@
module Otel := Opentelemetry
module Otrace := Trace_core
module TLS := Ambient_context_tls.TLS
module TLS := Thread_local_storage
(** [opentelemetry.trace] implements a {!Trace_core.Collector} for
{{:https://v3.ocaml.org/p/trace} ocaml-trace}.
@ -176,7 +176,7 @@ module Internal : sig
val create : unit -> t
val tls : t TLS.t
val k_tls : t TLS.t
val get : unit -> t
end