-
-
Notifications
You must be signed in to change notification settings - Fork 110
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
feat: add tracing helper #650
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.
What an interesting solution! I was not aware that we can solve the overshadowing problem by pointing to the error variable. The only rare cases I can think of where this would not work is when we create a second (inner) error variable:
func foo() (err error) {
if err := baz(); err != nil {
a, innerErr := bar()
if innerErr != nil {
return innerErr
}
return err
}
}
But in those cases, we can deal with the result in the code itself by introducing for example a second helper:
func foo() (err error) {
span, ctx := ...
defer End(span, &err)
if err := baz(); err != nil {
a, innerErr := bar()
if innerErr != nil {
return tracerx.TraceError(span, innerErr)
}
return err
}
}
Generally speaking, this solution is a 10x improvement to the callback one. I really like it :)
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.
Neat little trick 👍
675e2f8
to
8c2bcf5
Compare
This works with my solution 😊 I've added a test to show that. Golang will assign the return value (whatever it's name, if it even has one) to the named return value before running deferred calls, so this solution is always correct.
Thanks 🥰. |
No description provided.