-
Notifications
You must be signed in to change notification settings - Fork 50
Add updateAttributes as Span protocol requirement #203
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
base: main
Are you sure you want to change the base?
Add updateAttributes as Span protocol requirement #203
Conversation
There was a problem hiding this 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) {} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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