feat trace: add set_span_status

This commit is contained in:
Simon Cruanes 2025-12-10 14:42:50 -05:00
parent a2a7a6cf1e
commit 30175db1ed
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 14 additions and 1 deletions

View file

@ -14,6 +14,7 @@ module Extensions = struct
bt: Printexc.raw_backtrace; bt: Printexc.raw_backtrace;
} }
| Ev_set_span_kind of Otrace.explicit_span * OTEL.Span_kind.t | Ev_set_span_kind of Otrace.explicit_span * OTEL.Span_kind.t
| Ev_set_span_status of Otrace.explicit_span * OTEL.Span_status.t
end end
open Extensions open Extensions
@ -243,6 +244,10 @@ module Make_collector (A : COLLECTOR_ARG) = struct
(match get_span_ sp with (match get_span_ sp with
| None -> !on_internal_error "could not find scope for OTEL span" | None -> !on_internal_error "could not find scope for OTEL span"
| Some sc -> OTEL.Span.set_kind sc k) | Some sc -> OTEL.Span.set_kind sc k)
| Ev_set_span_status (sp, st) ->
(match get_span_ sp with
| None -> !on_internal_error "could not find scope for OTEL span"
| Some sc -> OTEL.Span.set_status sc st)
| Ev_record_exn { sp; exn; bt } -> | Ev_record_exn { sp; exn; bt } ->
(match get_span_ sp with (match get_span_ sp with
| None -> !on_internal_error "could not find scope for OTEL span" | None -> !on_internal_error "could not find scope for OTEL span"
@ -266,9 +271,13 @@ let link_spans (sp1 : Otrace.explicit_span) (sp2 : Otrace.explicit_span) : unit
if Otrace.enabled () then Otrace.extension_event @@ Ev_link_span (sp1, sp2) if Otrace.enabled () then Otrace.extension_event @@ Ev_link_span (sp1, sp2)
*) *)
let set_span_kind sp k : unit = let[@inline] set_span_kind sp k : unit =
if Otrace.enabled () then Otrace.extension_event @@ Ev_set_span_kind (sp, k) if Otrace.enabled () then Otrace.extension_event @@ Ev_set_span_kind (sp, k)
let[@inline] set_span_status sp status : unit =
if Otrace.enabled () then
Otrace.extension_event @@ Ev_set_span_status (sp, status)
let record_exception sp exn bt : unit = let record_exception sp exn bt : unit =
if Otrace.enabled () then if Otrace.enabled () then
Otrace.extension_event @@ Ev_record_exn { sp; exn; bt } Otrace.extension_event @@ Ev_record_exn { sp; exn; bt }

View file

@ -49,6 +49,7 @@ module Extensions : sig
} }
(** Record exception and potentially turn span to an error *) (** Record exception and potentially turn span to an error *)
| Ev_set_span_kind of Otrace.explicit_span * OTEL.Span_kind.t | Ev_set_span_kind of Otrace.explicit_span * OTEL.Span_kind.t
| Ev_set_span_status of Otrace.explicit_span * OTEL.Span_status.t
end end
val on_internal_error : (string -> unit) ref val on_internal_error : (string -> unit) ref
@ -92,6 +93,9 @@ val set_span_kind : Otrace.explicit_span -> OTEL.Span.kind -> unit
(** [set_span_kind sp k] sets the span's kind. (** [set_span_kind sp k] sets the span's kind.
@since 0.11 *) @since 0.11 *)
val set_span_status : Otrace.explicit_span -> OTEL.Span_status.t -> unit
(** @since NEXT_RELEASE *)
val record_exception : val record_exception :
Otrace.explicit_span -> exn -> Printexc.raw_backtrace -> unit Otrace.explicit_span -> exn -> Printexc.raw_backtrace -> unit
(** Record exception in the current span. (** Record exception in the current span.