mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-07 18:37:56 -05:00
Span.record_exception must also set the span status to error
This commit is contained in:
parent
e2fe0f6683
commit
05ef03b39d
3 changed files with 9 additions and 8 deletions
|
|
@ -103,17 +103,21 @@ let add_event' self ev : unit =
|
|||
let record_exception (self : t) (exn : exn) (bt : Printexc.raw_backtrace) : unit
|
||||
=
|
||||
if is_not_dummy self then (
|
||||
let exn_msg = Printexc.to_string exn in
|
||||
let ev =
|
||||
Event.make "exception"
|
||||
~attrs:
|
||||
[
|
||||
"exception.message", `String (Printexc.to_string exn);
|
||||
"exception.message", `String exn_msg;
|
||||
"exception.type", `String (Printexc.exn_slot_name exn);
|
||||
( "exception.stacktrace",
|
||||
`String (Printexc.raw_backtrace_to_string bt) );
|
||||
]
|
||||
in
|
||||
add_event self ev
|
||||
add_event self ev;
|
||||
|
||||
let status = make_status ~code:Status_code_error ~message:exn_msg () in
|
||||
span_set_status self status
|
||||
)
|
||||
|
||||
let add_attrs (self : t) (attrs : Key_value.t list) : unit =
|
||||
|
|
|
|||
|
|
@ -94,6 +94,8 @@ val add_event' : t -> (unit -> Event.t) -> unit
|
|||
it if there is an instrumentation backend. *)
|
||||
|
||||
val record_exception : t -> exn -> Printexc.raw_backtrace -> unit
|
||||
(** Record an exception occurring inside the span. This creates a span event
|
||||
{b and} also sets the span status to error. *)
|
||||
|
||||
val add_links : t -> Span_link.t list -> unit
|
||||
|
||||
|
|
|
|||
|
|
@ -94,12 +94,7 @@ let with_thunk_and_finally (self : Tracer.t) ?(force_new_trace_id = false)
|
|||
| None ->
|
||||
(match res with
|
||||
| Ok () -> ()
|
||||
| Error (e, bt) ->
|
||||
Span.record_exception span e bt;
|
||||
let status =
|
||||
make_status ~code:Status_code_error ~message:(Printexc.to_string e) ()
|
||||
in
|
||||
Span.set_status span status));
|
||||
| Error (e, bt) -> Span.record_exception span e bt));
|
||||
|
||||
Emitter.emit self.emit [ span ]
|
||||
in
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue