Skip to content

Commit 7b63d41

Browse files
committed
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.
1 parent b5d31f1 commit 7b63d41

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

opentelemetry-sdk/src/trace/events.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ impl IntoIterator for SpanEvents {
3131
}
3232

3333
impl SpanEvents {
34+
/// Create a new `SpanEvents` from a list of events and a dropped count
35+
pub fn new(events: Vec<Event>, dropped_count: u32) -> Self {
36+
Self {
37+
events,
38+
dropped_count,
39+
}
40+
}
41+
3442
pub(crate) fn add_event(&mut self, event: Event) {
3543
self.events.push(event);
3644
}

opentelemetry-sdk/src/trace/links.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ impl IntoIterator for SpanLinks {
3131
}
3232

3333
impl SpanLinks {
34+
/// Create a new `SpanLinks` from a list of events and a dropped count
35+
pub fn new(links: Vec<Link>, dropped_count: u32) -> Self {
36+
Self {
37+
links,
38+
dropped_count,
39+
}
40+
}
41+
3442
pub(crate) fn add_link(&mut self, link: Link) {
3543
self.links.push(link);
3644
}

0 commit comments

Comments
 (0)