ocaml-trace/test/tls/t_tls.real.ml
Simon Cruanes 42bf837113
add Trace_lwt optional library (#47)
* add Trace_lwt optional library

provides a with_span that's lwt friendly, as well as a ambient span
provider.

* test: extract recorder used for ambient tests

* tests for trace.lwt

* opam
2026-04-14 14:10:32 -04:00

24 lines
779 B
OCaml

(* Test ambient span tracking via thread-local-storage provider *)
open Test_trace_common
let ( let@ ) = ( @@ )
let () =
print_endline "=== ambient span (TLS) ===";
Trace_thread_local_storage.setup ();
let coll = make_recorder () in
let@ () = Trace_core.with_setup_collector coll in
Printf.printf "before any span: %s\n" (current_name ());
let@ _outer = Trace_core.with_span ~__FILE__ ~__LINE__ "outer" in
Printf.printf "in outer: %s\n" (current_name ());
(* inner span is scoped to just the one printf *)
(let@ _inner = Trace_core.with_span ~__FILE__ ~__LINE__ "inner" in
ignore _inner;
Printf.printf "in inner: %s\n" (current_name ()));
(* inner has exited, outer span is restored *)
Printf.printf "after inner exits: %s\n" (current_name ())