From 18226a63a4f235598fd979b3f2461ae08e7979f8 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Wed, 10 Dec 2025 14:37:30 -0500 Subject: [PATCH] add Span.dummy --- src/core/span.ml | 11 +++++++++-- src/core/span.mli | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/core/span.ml b/src/core/span.ml index 86f3826e..adbf3be8 100644 --- a/src/core/span.ml +++ b/src/core/span.ml @@ -44,6 +44,12 @@ let make ?(kind = !default_kind) ?trace_state ?(attrs = []) ?(events = []) in span +let dummy : t = + Proto.Trace.make_span + ~trace_id:Trace_id.(dummy |> to_bytes) + ~span_id:Span_id.(dummy |> to_bytes) + () + let create_new ?kind ?(id = Span_id.create ()) ?trace_state ?attrs ?events ?status ~trace_id ?parent ?links ~start_time ~end_time name : t = make ?kind ~id ~trace_id ?trace_state ?attrs ?events ?status ?parent ?links @@ -84,7 +90,8 @@ let[@inline] to_span_ctx (self : t) : Span_ctx.t = let[@inline] add_event self ev : unit = if is_not_dummy self then span_set_events self (ev :: self.events) -let add_event' self ev : unit = if is_not_dummy self then add_event self (ev ()) +let add_event' self ev : unit = + if is_not_dummy self then span_set_events self (ev () :: self.events) let record_exception (self : t) (exn : exn) (bt : Printexc.raw_backtrace) : unit = @@ -117,7 +124,7 @@ let add_attrs' (self : t) (attrs : unit -> Key_value.t list) : unit = ) let add_links (self : t) (links : Span_link.t list) : unit = - if links <> [] then ( + if is_not_dummy self && links <> [] then ( let links = List.rev_append links self.links in span_set_links self links ) diff --git a/src/core/span.mli b/src/core/span.mli index 0cd9478b..793b8ce1 100644 --- a/src/core/span.mli +++ b/src/core/span.mli @@ -51,6 +51,9 @@ val trace_id : t -> Trace_id.t val is_not_dummy : t -> bool +val dummy : t +(** Dummy span, will not record anything *) + val create_new : ?kind:kind -> ?id:Span_id.t ->