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; do_sth y;
begin begin
let _trace_span = Trace_core.enter_span ~__FILE__ ~__LINE__ "sub-span" in let _trace_span = Trace_core.enter_span ~__FILE__ ~__LINE__ "sub-span" in
try match do_sth z with
let _res = do_sth z in | res ->
Trace_core.exit_span _trace_span; Trace_core.exit_span _trace_span;
_res res
with e -> | exception e ->
Trace_core.exit_span _trace_span Trace_core.exit_span _trace_span
raise e raise e
end; end;

View file

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

View file

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