ppx: make sure to reconstruct backtraces

This commit is contained in:
Simon Cruanes 2023-12-22 21:38:31 -05:00
parent 78edd779d4
commit bb520d90b5
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
3 changed files with 11 additions and 10 deletions

View file

@ -100,11 +100,11 @@ let f x y z =
do_sth y;
begin
let _trace_span = Trace_core.enter_span ~__FILE__ ~__LINE__ "sub-span" in
try
let _res = do_sth z in
match do_sth z with
| res ->
Trace_core.exit_span _trace_span;
_res
with e ->
res
| exception e ->
Trace_core.exit_span _trace_span
raise e
end;

View file

@ -9,7 +9,7 @@ tags: ["trace" "tracing" "observability" "profiling" "ppx"]
homepage: "https://github.com/c-cube/ocaml-trace"
bug-reports: "https://github.com/c-cube/ocaml-trace/issues"
depends: [
"ocaml" {>= "4.08"}
"ocaml" {>= "4.12"}
"ppxlib"
"trace" {= version}
"trace-tef" {= version & with-test}

View file

@ -52,13 +52,14 @@ let expand_top_let ~ctxt rec_flag (vbs : _ list) =
let _trace_span =
Trace_core.enter_span ~__FILE__ ~__LINE__ __FUNCTION__
in
try
let _trace_ppx_res = [%e e] in
match [%e e] with
| res ->
Trace_core.exit_span _trace_span;
__trace_ppx_res
with exn ->
res
| exception exn ->
let bt = Printexc.get_raw_backtrace () in
Trace_core.exit_span _trace_span;
raise exn]
Printexc.raise_with_backtrace exn bt]
in
let tr_vb (vb : value_binding) : value_binding =