mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-08 20:07:55 -04:00
Merge pull request #63 from tatchi/add-record-exception
add record_exception
This commit is contained in:
commit
9680d61a36
2 changed files with 25 additions and 8 deletions
|
|
@ -776,6 +776,21 @@ module Scope = struct
|
||||||
let[@inline] add_event (scope : t) (ev : unit -> Event.t) : unit =
|
let[@inline] add_event (scope : t) (ev : unit -> Event.t) : unit =
|
||||||
if Collector.has_backend () then scope.events <- ev () :: scope.events
|
if Collector.has_backend () then scope.events <- ev () :: scope.events
|
||||||
|
|
||||||
|
let[@inline] record_exception (scope : t) (exn : exn)
|
||||||
|
(bt : Printexc.raw_backtrace) : unit =
|
||||||
|
if Collector.has_backend () then (
|
||||||
|
let ev =
|
||||||
|
Event.make "exception"
|
||||||
|
~attrs:
|
||||||
|
[
|
||||||
|
"message", `String (Printexc.to_string exn);
|
||||||
|
"type", `String (Printexc.exn_slot_name exn);
|
||||||
|
"stacktrace", `String (Printexc.raw_backtrace_to_string bt);
|
||||||
|
]
|
||||||
|
in
|
||||||
|
scope.events <- ev :: scope.events
|
||||||
|
)
|
||||||
|
|
||||||
(** Add an attr to the scope. It will be aggregated into the span.
|
(** Add an attr to the scope. It will be aggregated into the span.
|
||||||
|
|
||||||
Note that this takes a function that produces attributes, and will only
|
Note that this takes a function that produces attributes, and will only
|
||||||
|
|
@ -1032,11 +1047,9 @@ module Trace = struct
|
||||||
| Ok () -> default_status ~code:Status_code_ok ()
|
| Ok () -> default_status ~code:Status_code_ok ()
|
||||||
| Error (e, bt) ->
|
| Error (e, bt) ->
|
||||||
(* add backtrace *)
|
(* add backtrace *)
|
||||||
add_event scope (fun () ->
|
Scope.record_exception scope e bt;
|
||||||
Event.make "error"
|
default_status ~code:Status_code_error ~message:(Printexc.to_string e)
|
||||||
~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
|
||||||
|
|
@ -1084,7 +1097,7 @@ module Trace = struct
|
||||||
rv
|
rv
|
||||||
with e ->
|
with e ->
|
||||||
let bt = Printexc.get_raw_backtrace () in
|
let bt = Printexc.get_raw_backtrace () in
|
||||||
finally (Error (Printexc.to_string e, bt));
|
finally (Error (e, bt));
|
||||||
raise e
|
raise e
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,10 @@ module GC_metrics = GC_metrics
|
||||||
module Metrics_callbacks = Metrics_callbacks
|
module Metrics_callbacks = Metrics_callbacks
|
||||||
module Trace_context = Trace_context
|
module Trace_context = Trace_context
|
||||||
|
|
||||||
|
external reraise : exn -> 'a = "%reraise"
|
||||||
|
(** This is equivalent to [Lwt.reraise]. We inline it here so we don't force
|
||||||
|
to use Lwt's latest version *)
|
||||||
|
|
||||||
module Trace = struct
|
module Trace = struct
|
||||||
include Trace
|
include Trace
|
||||||
|
|
||||||
|
|
@ -29,8 +33,8 @@ module Trace = struct
|
||||||
Lwt.return rv
|
Lwt.return rv
|
||||||
with e ->
|
with e ->
|
||||||
let bt = Printexc.get_raw_backtrace () in
|
let bt = Printexc.get_raw_backtrace () in
|
||||||
let () = finally (Error (Printexc.to_string e, bt)) in
|
let () = finally (Error (e, bt)) in
|
||||||
Lwt.fail e
|
reraise e
|
||||||
end
|
end
|
||||||
|
|
||||||
module Metrics = struct
|
module Metrics = struct
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue