Skip to content

Conversation

@adam-fowler
Copy link
Contributor

@adam-fowler adam-fowler commented Dec 18, 2025

Add updateAttributes(_:) as Span protocol requirement
The majority of Span implementations will use the default implementation
Adding the function to the protocol though allows us to override the function for the NoOpSpan

Fix for #189

@ktoso ktoso added the 🆕 semver/minor Adds new public API. label Dec 19, 2025
Copy link
Member

@ktoso ktoso left a comment

Choose a reason for hiding this comment

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

LGTM, this works fine because the default impl already exists; so this will be source compatible, which is the only guarantee we need here;

Therefore we can disregard the API break warning, it doesn't understand the default impl

///
/// The NoOpSpan implementation does not call the closure as setting attributes
/// on a NoOpSpan does nothing.
public func updateAttributes(_ update: (inout SpanAttributes) -> Void) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm see my other comment, I still think we should call the closure, just with local empty span attributes that get discarded immediately, not saved on the instance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We then allocate space for attributes ie the ones we setup inside the closure and then throw them away immediately. It appears on godbolt the compiler isn't clever enough to compile out the creation of the attributes.

Copy link
Contributor

Choose a reason for hiding this comment

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

My lean would be that we just live with that cost and file an issue on the compiler to improve this.

But when correctness and performance are in tension, and we're locking this decision in a public API, I think we should choose correctness here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🆕 semver/minor Adds new public API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants