Skip to content

Commit

Permalink
fix otel.trace: record exception in with_span
Browse files Browse the repository at this point in the history
close #71
  • Loading branch information
c-cube committed Oct 16, 2024
1 parent 974ce75 commit b720ea0
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/trace/opentelemetry_trace.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Otel.Scope.record_exception sb.scope e bt;
let otel_span = exit_span' otrace_id sb in
Otel.Trace.emit [ otel_span ];

let otel_span = exit_span' otrace_id sb in
Otel.Trace.emit [ otel_span ];
rv
Printexc.raise_with_backtrace e bt

let enter_span ~__FUNCTION__ ~__FILE__ ~__LINE__ ~data name :
Trace_core.span =
Expand Down

0 comments on commit b720ea0

Please sign in to comment.