mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-13 14:06:32 -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 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
|
?(attrs : (string * [< value ]) list = []) ?kind ?trace_id ?parent ?scope
|
||||||
?links name cb =
|
?links name cb =
|
||||||
let scope =
|
let scope =
|
||||||
|
|
@ -781,7 +781,13 @@ module Trace = struct
|
||||||
let status =
|
let status =
|
||||||
match res with
|
match res with
|
||||||
| Ok () -> default_status ~code:Status_code_ok ()
|
| 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
|
in
|
||||||
let span, _ =
|
let span, _ =
|
||||||
(* TODO: should the attrs passed to with_ go on the 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
|
let with_ ?force_new_trace_id ?trace_state ?service_name ?attrs ?kind
|
||||||
?trace_id ?parent ?scope ?links name (cb : Scope.t -> 'a) : 'a =
|
?trace_id ?parent ?scope ?links name (cb : Scope.t -> 'a) : 'a =
|
||||||
let thunk, finally =
|
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
|
?trace_id ?parent ?scope ?links name cb
|
||||||
in
|
in
|
||||||
|
|
||||||
|
|
@ -828,7 +834,8 @@ module Trace = struct
|
||||||
finally (Ok ());
|
finally (Ok ());
|
||||||
rv
|
rv
|
||||||
with e ->
|
with e ->
|
||||||
finally (Error (Printexc.to_string e));
|
let bt = Printexc.get_raw_backtrace () in
|
||||||
|
finally (Error (Printexc.to_string e, bt));
|
||||||
raise e
|
raise e
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue