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

Conversation

paullegranddc
Copy link
Contributor

Even though all fields are public, because of the #[non_exhaustive] annotation on SpanEventsand 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.

Changes

Add public constructors on SpanEvents and SpanLinks structs.

Merge requirement checklist

  • CONTRIBUTING guidelines followed
  • Unit tests added/updated (if applicable)
  • Appropriate CHANGELOG.md files updated for non-trivial, user-facing changes
  • Changes in public API reviewed (if applicable)

# 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.
@paullegranddc paullegranddc requested a review from a team as a code owner April 18, 2025 11:49
Copy link

codecov bot commented Apr 18, 2025

Codecov Report

Attention: Patch coverage is 0% with 12 lines in your changes missing coverage. Please review.

Project coverage is 81.3%. Comparing base (b5d31f1) to head (7b63d41).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
opentelemetry-sdk/src/trace/events.rs 0.0% 6 Missing ⚠️
opentelemetry-sdk/src/trace/links.rs 0.0% 6 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main   #2934     +/-   ##
=======================================
- Coverage   81.3%   81.3%   -0.1%     
=======================================
  Files        126     126             
  Lines      24254   24266     +12     
=======================================
  Hits       19736   19736             
- Misses      4518    4530     +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@@ -31,6 +31,14 @@ impl IntoIterator for SpanLinks {
}

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants