mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-07 18:37:56 -05:00
fire-and-forget sending of spans to collector so we dont block userland
This commit is contained in:
parent
1a2b3aa398
commit
b52d9d02e0
1 changed files with 3 additions and 11 deletions
|
|
@ -12,14 +12,6 @@ module Trace = struct
|
||||||
open Proto.Trace
|
open Proto.Trace
|
||||||
include Trace
|
include Trace
|
||||||
|
|
||||||
(** Emit asynchronously *)
|
|
||||||
let emit ?service_name ?attrs (spans:span list) : unit Lwt.t =
|
|
||||||
let fut, wake = Lwt.wait() in
|
|
||||||
let rs = make_resource_spans ?service_name ?attrs spans in
|
|
||||||
Collector.send_trace [rs]
|
|
||||||
~over:(fun () -> Lwt.wakeup_later wake ())
|
|
||||||
~ret:(fun () -> fut)
|
|
||||||
|
|
||||||
(** Sync span guard *)
|
(** Sync span guard *)
|
||||||
let with_
|
let with_
|
||||||
?trace_state ?service_name ?(attrs=[])
|
?trace_state ?service_name ?(attrs=[])
|
||||||
|
|
@ -44,10 +36,10 @@ module Trace = struct
|
||||||
Lwt.catch
|
Lwt.catch
|
||||||
(fun () ->
|
(fun () ->
|
||||||
let* x = f scope in
|
let* x = f scope in
|
||||||
let+ () = finally (Ok ()) in
|
let () = finally (Ok ()) in
|
||||||
x)
|
Lwt.return x)
|
||||||
(fun e ->
|
(fun e ->
|
||||||
let* () = finally (Error (Printexc.to_string e)) in
|
let () = finally (Error (Printexc.to_string e)) in
|
||||||
Lwt.fail e)
|
Lwt.fail e)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue