[SDK] Handle instrumentation object construction failures safely - #4469
Draft
22elix3r wants to merge 1 commit into
Draft
[SDK] Handle instrumentation object construction failures safely#446922elix3r wants to merge 1 commit into
22elix3r wants to merge 1 commit into
Conversation
Remove noexcept from SDK TracerProvider, LoggerProvider, MeterProvider, Tracer, Logger, and Meter constructors so initialization-time allocation failures can propagate. Keep GetTracer/GetLogger/GetMeter noexcept and return a pre-allocated noop object if constructing a new instrumentation object fails, without caching the failed attempt. Fixes open-telemetry#4361 Signed-off-by: elix3r <157088510+22elix3r@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4469 +/- ##
==========================================
- Coverage 82.62% 82.59% -0.03%
==========================================
Files 512 512
Lines 20139 20194 +55
==========================================
+ Hits 16638 16677 +39
- Misses 3501 3517 +16
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4361
Changes
Provider construction happens during SDK initialization. Runtime
GetTracer/GetLogger/GetMetercalls must not throw. This change follows the post-SIG direction from @dbarker:noexceptfrom the SDK constructors forTracerProvider,LoggerProvider,MeterProvider,Tracer,Logger, andMeter. Allocation or initialization failures during provider construction can now propagate so the caller (often the configuration library) can handle them.GetTracer,GetLogger, andGetMeternoexcept. If constructing a previously unseen tracer/logger/meter fails, the provider catches the exception (when exceptions are enabled), logs viaOTEL_INTERNAL_LOG_ERRORwithout letting logging escape, and returns a valid noop API object.new NoopTracer/NoopLogger/NoopMeterstored as anostd::shared_ptr). Runtime failure handling does not allocate a fresh noop object.Get*call can retry and return a normal SDK object once the failure is gone. Existing cached objects continue to be returned unchanged.shared_ptrcontrol-block allocation, cache insertion, and metricsAddMeter.Get*signatures are unchanged. Try/catch is compiled only whenOPENTELEMETRY_HAVE_EXCEPTIONSis set.Tests added
noexceptstatic_asserts for each signal.ScopeConfiguratormatcher that throws for a named scope.Get*returns a valid noop-compatible object, using it produces no telemetry, the cache is not poisoned, cached objects are unchanged, and a later call recovers when the injected failure is removed.Validation
tools/format.shwas not run:clang-formatis not installed in this environment.CHANGELOG.mdupdated for non-trivial changesGet*contracts unchanged)