mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-08 03:47:59 -04:00
feat: record backtraces in error spans
This commit is contained in:
parent
abafac8361
commit
479f1f39c8
1 changed files with 11 additions and 4 deletions
|
|
@ -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 =
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue