[API] reduce allocation in no span case#4254
Conversation
…to perf-get-span-context
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4254 +/- ##
==========================================
- Coverage 78.15% 78.15% -0.00%
==========================================
Files 440 440
Lines 18741 18736 -5
==========================================
- Hits 14645 14641 -4
+ Misses 4096 4095 -1
🚀 New features to boost your workflow:
|
dbarker
left a comment
There was a problem hiding this comment.
Looks good to me. Thanks for the PR!
It needs additional review and approval as this is an expansion of the API.
| const context::Context &context) noexcept override | ||
| { | ||
| SpanContext span_context = trace::GetSpan(context)->GetContext(); | ||
| SpanContext span_context = trace::GetSpanContext(context); |
There was a problem hiding this comment.
Not an ABI break. No observable behavior change.
|
Do not merge: Release 1.28.0 needs to be published first, and this PR can be merged after. This is to limit last minute changes to API just when releasing. |
|
|
||
| // Get the span metadata from the active span in the context. | ||
| if (const nostd::shared_ptr<Span> *maybe_span = | ||
| nostd::get_if<nostd::shared_ptr<Span>>(&context_value)) |
There was a problem hiding this comment.
Could the active variant alternative contain an empty nostd::shared_ptr<Span> here? nostd::get_if would still return a non-null pointer to the stored shared_ptr, so this condition would succeed even though *maybe_span is null, and the next line would dereference it.
The same issue applies to maybe_span_context below. Should both branches also check that the stored shared_ptr is non-null and return SpanContext::GetInvalid() otherwise?
Changes
Comment: #4191 (comment)
Reducing allocation in the no span case. Because a new default span
return nostd::shared_ptr<Span>(new DefaultSpan(SpanContext::GetInvalid()));is created when we get context formGetSpan.CHANGELOG.mdupdated for non-trivial changes