small test for span tracking

This commit is contained in:
Simon Cruanes 2026-01-17 20:54:22 -05:00
parent f88cd7651c
commit bb78e9babb
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
3 changed files with 28 additions and 0 deletions

View file

@ -11,3 +11,8 @@
(preprocess
(pps ppx_trace))
(libraries trace-tef))
(test
(name t_debug)
(modules t_debug)
(libraries trace trace.debug trace-tef))

4
test/t_debug.expected Normal file
View file

@ -0,0 +1,4 @@
[{"pid":2,"cat":"","tid": 3,"dur": 4.00,"ts": 0.00,"name":"main","ph":"X"}trace: warning: 3 spans were not closed
span "sp1" was not closed (2 occurrences)
span "sp2" was not closed (1 occurrences)
]

19
test/t_debug.ml Normal file
View file

@ -0,0 +1,19 @@
let ( let@ ) = ( @@ )
let main () =
let@ _sp = Trace.with_span ~__FILE__ ~__LINE__ "main" in
let _sp1 = Trace.enter_span ~__FILE__ ~__LINE__ "sp1" in
let _sp2 = Trace.enter_span ~__FILE__ ~__LINE__ "sp2" in
let _sp1' = Trace.enter_span ~__FILE__ ~__LINE__ "sp1" in
()
let () =
Trace_tef.Private_.mock_all_ ();
let@ () =
Trace.with_setup_collector
(Trace_tef.collector ~out:`Stdout ()
|> Trace_debug.Track_spans.track ~on_lingering_spans:(`Out stdout))
in
main ()