Skip to content

Commit

Permalink
ppx: make sure to reconstruct backtraces
Browse files Browse the repository at this point in the history
  • Loading branch information
c-cube committed Dec 23, 2023
1 parent 78edd77 commit bb520d9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion ppx_trace.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
11 changes: 6 additions & 5 deletions src/ppx/ppx_trace.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit bb520d9

Please sign in to comment.