Skip to content

Commit

Permalink
feat: record backtraces in error spans
Browse files Browse the repository at this point in the history
  • Loading branch information
c-cube committed Feb 9, 2024
1 parent abafac8 commit 479f1f3
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/core/opentelemetry.ml
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ module Trace = struct

let add_attrs = Scope.add_attrs [@@deprecated "use Scope.add_attrs"]

let with_' ?(force_new_trace_id = false) ?trace_state ?service_name
let with_ ?(force_new_trace_id = false) ?trace_state ?service_name
?(attrs : (string * [< value ]) list = []) ?kind ?trace_id ?parent ?scope
?links name cb =
let scope =
Expand Down Expand Up @@ -781,7 +781,13 @@ module Trace = struct
let status =
match res with
| Ok () -> default_status ~code:Status_code_ok ()
| Error e -> default_status ~code:Status_code_error ~message:e ()
| Error (e, bt) ->
(* add backtrace *)
add_event scope (fun () ->
Event.make "error"
~attrs:
[ "backtrace", `String (Printexc.raw_backtrace_to_string bt) ]);
default_status ~code:Status_code_error ~message:e ()
in
let span, _ =
(* TODO: should the attrs passed to with_ go on the Span
Expand Down Expand Up @@ -819,7 +825,7 @@ module Trace = struct
let with_ ?force_new_trace_id ?trace_state ?service_name ?attrs ?kind
?trace_id ?parent ?scope ?links name (cb : Scope.t -> 'a) : 'a =
let thunk, finally =
with_' ?force_new_trace_id ?trace_state ?service_name ?attrs ?kind
with_ ?force_new_trace_id ?trace_state ?service_name ?attrs ?kind
?trace_id ?parent ?scope ?links name cb
in

Expand All @@ -828,7 +834,8 @@ module Trace = struct
finally (Ok ());
rv
with e ->
finally (Error (Printexc.to_string e));
let bt = Printexc.get_raw_backtrace () in
finally (Error (Printexc.to_string e, bt));
raise e
end

Expand Down

0 comments on commit 479f1f3

Please sign in to comment.