Add updateAttributes as Span protocol requirement#203
Open
adam-fowler wants to merge 3 commits intoapple:mainfrom
Open
Add updateAttributes as Span protocol requirement#203adam-fowler wants to merge 3 commits intoapple:mainfrom
adam-fowler wants to merge 3 commits intoapple:mainfrom
Conversation
ktoso
approved these changes
Dec 19, 2025
czechboy0
reviewed
Dec 19, 2025
| /// | ||
| /// The NoOpSpan implementation does not call the closure as setting attributes | ||
| /// on a NoOpSpan does nothing. | ||
| public func updateAttributes(_ update: (inout SpanAttributes) -> Void) {} |
Contributor
There was a problem hiding this comment.
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.
Contributor
Author
There was a problem hiding this comment.
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.
Contributor
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
updateAttributes(_:)as Span protocol requirementThe majority of Span implementations will use the default implementation
Adding the function to the protocol though allows us to override the function for the
NoOpSpanFix for #189