Skip to content

feat(opentelemetry-sdk): add a constructor for SpanEvents and SpanLinks #2934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions opentelemetry-sdk/src/trace/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
}

impl SpanEvents {
/// Create a new `SpanEvents` from a list of events and a dropped count
pub fn new(events: Vec<Event>, dropped_count: u32) -> Self {
Self {
events,
dropped_count,
}
}

Check warning on line 40 in opentelemetry-sdk/src/trace/events.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/trace/events.rs#L35-L40

Added lines #L35 - L40 were not covered by tests

pub(crate) fn add_event(&mut self, event: Event) {
self.events.push(event);
}
Expand Down
8 changes: 8 additions & 0 deletions opentelemetry-sdk/src/trace/links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
}

impl SpanLinks {
/// Create a new `SpanLinks` from a list of events and a dropped count
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it only required for tests?

Copy link
Contributor Author

@paullegranddc paullegranddc Apr 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I need it for tests, but there are definitely wider use cases.
For instance you could imagine span processors or span exporters trying to create "synthetic spans" and put span links and span events on these synthetic spans.

This currently doesn't work, and I can't think of a good rational as to why creating SpanData without span events should not be possible, and not with them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This currently doesn't work, and I can't think of a good rational as to why creating SpanData without span events should not be possible, and not with them.

It feels like there is one too many negations here. I assume you're saying that if it's possible to create SpanData without SpanLinks and SpanEvents, then it should be possible to create SpanData with them.

pub fn new(links: Vec<Link>, dropped_count: u32) -> Self {
Self {
links,
dropped_count,
}
}

Check warning on line 40 in opentelemetry-sdk/src/trace/links.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/trace/links.rs#L35-L40

Added lines #L35 - L40 were not covered by tests

pub(crate) fn add_link(&mut self, link: Link) {
self.links.push(link);
}
Expand Down