Span.record_exception must also set the span status to error

This commit is contained in:
Simon Cruanes 2026-03-05 10:22:57 -05:00
parent e2fe0f6683
commit 05ef03b39d
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
3 changed files with 9 additions and 8 deletions

View file

@ -103,17 +103,21 @@ let add_event' self ev : unit =
let record_exception (self : t) (exn : exn) (bt : Printexc.raw_backtrace) : unit let record_exception (self : t) (exn : exn) (bt : Printexc.raw_backtrace) : unit
= =
if is_not_dummy self then ( if is_not_dummy self then (
let exn_msg = Printexc.to_string exn in
let ev = let ev =
Event.make "exception" Event.make "exception"
~attrs: ~attrs:
[ [
"exception.message", `String (Printexc.to_string exn); "exception.message", `String exn_msg;
"exception.type", `String (Printexc.exn_slot_name exn); "exception.type", `String (Printexc.exn_slot_name exn);
( "exception.stacktrace", ( "exception.stacktrace",
`String (Printexc.raw_backtrace_to_string bt) ); `String (Printexc.raw_backtrace_to_string bt) );
] ]
in 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 = let add_attrs (self : t) (attrs : Key_value.t list) : unit =

View file

@ -94,6 +94,8 @@ val add_event' : t -> (unit -> Event.t) -> unit
it if there is an instrumentation backend. *) it if there is an instrumentation backend. *)
val record_exception : t -> exn -> Printexc.raw_backtrace -> unit 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 val add_links : t -> Span_link.t list -> unit

View file

@ -94,12 +94,7 @@ let with_thunk_and_finally (self : Tracer.t) ?(force_new_trace_id = false)
| None -> | None ->
(match res with (match res with
| Ok () -> () | Ok () -> ()
| Error (e, bt) -> | Error (e, bt) -> Span.record_exception span 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));
Emitter.emit self.emit [ span ] Emitter.emit self.emit [ span ]
in in