Add SpanContextFromContext()#1255
Conversation
fff6f3e to
3d18410
Compare
Codecov Report
@@ Coverage Diff @@
## master #1255 +/- ##
======================================
Coverage 76.9% 76.9%
======================================
Files 122 122
Lines 5924 5927 +3
======================================
+ Hits 4557 4561 +4
Misses 1120 1120
+ Partials 247 246 -1
|
Aneurysm9
left a comment
There was a problem hiding this comment.
I'm not sure how I feel about this change. Particularly with the addition of SpanContextFromContext() it seems like just moving things around. It seems to me that the better experience is to have SpanFromContext() always return a usable span, even if it is no-op. If an instrumentor is concerned with avoiding expensive operations for non-recording or no-op spans then the span.IsRecording() method is available to them.
|
After discussing this during the SIG meeting we came to the conclusion that adding |
|
I don't understand the meaning that In that situation, users can only invoke I think users can easily use |
Looked at another way, what value does knowing whether the
It can be done, but it doesn't need to be done and it is a better DX to not require it be done. Also, since it has not been required to this point we should assume that there is a significant body of code out there already that doesn't perform any such check and will be susceptible to runtime errors attempting to invoke methods on |
I agree with this statement, and was going to ask if it wouldn't be safer for SpanFromContext not to return nil. |
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
94791ac to
ab32e80
Compare
* SpanFromContext returns nil if span not exists
* Add tests for SpanContextFromContext
* Update CHANGELOG
* Update trace.go
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
* SpanFromContext() continue to return a noopSpan{}
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Resolves #1251
Many places use a way to attain
SpanContext, and it will panic ifSpanFromContext()returns nil.So, I add a new API
SpanContextFromContextto replace that part without worry about panic.