From 7b63d4172992a7f01b59d57a845664ca9bc0e64c Mon Sep 17 00:00:00 2001 From: paullegranddc Date: Fri, 18 Apr 2025 13:45:58 +0200 Subject: [PATCH] feat(opentelemetry-sdk): add a constructor for SpanEvents and SpanLinks # Changes Add public constructors on SpanEvents and SpanLinks structs. # Motivation Even though all fields are public, because of the `#[non_exhaustive]` annotation on `SpanEvents`and `SpanLinks`, it's not possible to construct instances of these outside of the `opentelemetry-sdk` crate. Since they are used in `export::SpanData`, it is problematic because it means there is no way to create span data containing any events or span links. So there is no way to write tests on how to these fields are processed in external crate that implement the SpanExporter or SpanProcessor traits. --- opentelemetry-sdk/src/trace/events.rs | 8 ++++++++ opentelemetry-sdk/src/trace/links.rs | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/opentelemetry-sdk/src/trace/events.rs b/opentelemetry-sdk/src/trace/events.rs index fbf2bcb928..8eb9532815 100644 --- a/opentelemetry-sdk/src/trace/events.rs +++ b/opentelemetry-sdk/src/trace/events.rs @@ -31,6 +31,14 @@ impl IntoIterator for SpanEvents { } impl SpanEvents { + /// Create a new `SpanEvents` from a list of events and a dropped count + pub fn new(events: Vec, dropped_count: u32) -> Self { + Self { + events, + dropped_count, + } + } + pub(crate) fn add_event(&mut self, event: Event) { self.events.push(event); } diff --git a/opentelemetry-sdk/src/trace/links.rs b/opentelemetry-sdk/src/trace/links.rs index 33d8074fa3..bed64f5ab5 100644 --- a/opentelemetry-sdk/src/trace/links.rs +++ b/opentelemetry-sdk/src/trace/links.rs @@ -31,6 +31,14 @@ impl IntoIterator for SpanLinks { } impl SpanLinks { + /// Create a new `SpanLinks` from a list of events and a dropped count + pub fn new(links: Vec, dropped_count: u32) -> Self { + Self { + links, + dropped_count, + } + } + pub(crate) fn add_link(&mut self, link: Link) { self.links.push(link); }