fix otel.trace: record exception in with_span

close #71
This commit is contained in:
Simon Cruanes 2024-10-16 13:08:54 -04:00
parent f8079a13ea
commit 041d05eb9f

View file

@ -200,11 +200,19 @@ module Internal = struct
in
Otel.Scope.with_ambient_scope sb.scope @@ fun () ->
let rv = cb otrace_id in
match cb otrace_id with
| res ->
let otel_span = exit_span' otrace_id sb in
Otel.Trace.emit [ otel_span ];
res
| exception e ->
let bt = Printexc.get_raw_backtrace () in
let otel_span = exit_span' otrace_id sb in
Otel.Trace.emit [ otel_span ];
rv
Otel.Scope.record_exception sb.scope e bt;
let otel_span = exit_span' otrace_id sb in
Otel.Trace.emit [ otel_span ];
Printexc.raise_with_backtrace e bt
let enter_span ~__FUNCTION__ ~__FILE__ ~__LINE__ ~data name :
Trace_core.span =