From 30175db1ed3e1589a5cb782c68766be5c249c881 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Wed, 10 Dec 2025 14:42:50 -0500 Subject: [PATCH] feat trace: add set_span_status --- src/trace/opentelemetry_trace.ml | 11 ++++++++++- src/trace/opentelemetry_trace.mli | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/trace/opentelemetry_trace.ml b/src/trace/opentelemetry_trace.ml index 31f87c5c..c3891140 100644 --- a/src/trace/opentelemetry_trace.ml +++ b/src/trace/opentelemetry_trace.ml @@ -14,6 +14,7 @@ module Extensions = struct bt: Printexc.raw_backtrace; } | 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 open Extensions @@ -243,6 +244,10 @@ module Make_collector (A : COLLECTOR_ARG) = struct (match get_span_ sp with | None -> !on_internal_error "could not find scope for OTEL span" | 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 } -> (match get_span_ sp with | 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) *) -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) +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 = if Otrace.enabled () then Otrace.extension_event @@ Ev_record_exn { sp; exn; bt } diff --git a/src/trace/opentelemetry_trace.mli b/src/trace/opentelemetry_trace.mli index f4045f79..737fc015 100644 --- a/src/trace/opentelemetry_trace.mli +++ b/src/trace/opentelemetry_trace.mli @@ -49,6 +49,7 @@ module Extensions : sig } (** Record exception and potentially turn span to an error *) | 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 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. @since 0.11 *) +val set_span_status : Otrace.explicit_span -> OTEL.Span_status.t -> unit +(** @since NEXT_RELEASE *) + val record_exception : Otrace.explicit_span -> exn -> Printexc.raw_backtrace -> unit (** Record exception in the current span.