Repository navigation
[SDK] Remove noexcept from the SDK Span constructor - #4700
akshat-lakhera wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4700 +/- ##
==========================================
- Coverage 86.81% 86.77% -0.04%
==========================================
Files 525 525
Lines 20736 20759 +23
==========================================
+ Hits 18000 18011 +11
- Misses 2736 2748 +12
🚀 New features to boost your workflow:
|
|
@akshat-lakhera - Thanks for working on this. Could we handle the failure inside |
9b5e717 to
f167d33
Compare
|
@lalitb Updated in f167d33. The Span constructor keeps noexcept now, and the allocation failure is handled inside MakeRecordable() instead: MultiSpanProcessor and the span exporters (ostream, in-memory, OTLP gRPC/HTTP/file, Zipkin) catch it and return nullptr, which the Span constructor already treats as a non-recording span. MultiSpanProcessor also skips a child that returns null, since MultiRecordable forwards every setter to its children and would dereference it. Added MultiSpanProcessorTest.MakeRecordableSkipsChildWithoutRecordable as a regression test. It segfaults on the old code and passes now. |
|
Looks good overall. One small suggestion: could we add a test that forces the span allocation to fail and verifies that extraction preserves the original context? Since noexcept handling is being discussed in #3013, @marcalff, it would be helpful to get your view on the new allocation failure fallback here. |
ac32523 to
1fdcf7a
Compare
|
@lalitb added Tracer.FailedSpanAllocationPreservesContextOnExtract in tracer_test.cc. It makes the MultiRecordable allocation throw bad_alloc once through a replacement operator new (only when exceptions are enabled), then checks that StartSpan returns a non-recording span that still has the parent trace id, a new span id and the sampled flag. After injecting it with HttpTraceContext and extracting it again, the trace id, span id and flags are unchanged, and the next span on the tracer records normally. Without the MakeRecordable change the test terminates on the bad_alloc. Also rebased onto main; the only conflict was CHANGELOG.md. |
db1670b to
ad30c49
Compare
Signed-off-by: Akshat Lakhera <akshatlnct2024@gmail.com>
ad30c49 to
536f475
Compare
Fixes #4685
Changes
The SDK Span constructor was marked noexcept but allocates (recordable, name, attributes, links), so a bad_alloc would call std::terminate and take down the host application. Tracer::StartSpan already catches exceptions and returns a no-op span, so this removes noexcept from the constructor and lets the exception reach that handler. Builds without exceptions are unchanged.
No unit test added: every callback the constructor invokes is itself noexcept, so a bad_alloc cannot be injected without terminating.
For significant contributions please make sure you have completed the following items: