[CODE HEALTH] Fix clang-tidy bugprone-exception-escape in ostream exporters#4137
Open
jensecrest wants to merge 3 commits into
Open
[CODE HEALTH] Fix clang-tidy bugprone-exception-escape in ostream exporters#4137jensecrest wants to merge 3 commits into
jensecrest wants to merge 3 commits into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4137 +/- ##
==========================================
- Coverage 82.02% 81.89% -0.13%
==========================================
Files 385 385
Lines 16071 16095 +24
==========================================
- Hits 13181 13179 -2
- Misses 2890 2916 +26
🚀 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 #2053
Changes
Fixes 3
bugprone-exception-escapeclang-tidy warnings in the ostream exporters by wrapping the throwing portions ofExportintry/catch, guarded by#if OPENTELEMETRY_HAVE_EXCEPTIONS.OStreamLogRecordExporter::Exportinlog_record_exporter.ccOStreamSpanExporter::Exportinspan_exporter.ccOStreamMetricExporter::Exportinmetric_exporter.ccWhat the problem is
All three
Exportfunctions are markednoexcept(required by their base class interfaces), but contain operations that can throw:sout_ << ...—std::ostream::operator<<can throwstd::ios_base::failureif exceptions are enabled on the streamstd::string(char*, len)construction — can throwstd::bad_allocprintAttributes,printEvents,printInstrumentationInfoMetricData— all use ostream internallyIf any of these throw inside a
noexceptfunction, the program callsstd::terminate()— a crash.Why try/catch is the minimal fix
noexcept— it's on the pure virtual base class interfaces (LogRecordExporter,SpanExporter,PushMetricExporter). Changing it would be an API/ABI break.operator<<orstd::stringconstruction. The entire purpose of these functions is to write to an ostream.try/catchis the established pattern in this codebase — seePeriodicExportingMetricReader::CollectAndExportOnce()inperiodic_exporting_metric_reader.cc, which uses the same#if OPENTELEMETRY_HAVE_EXCEPTIONS/try/catchstructure.What the change does
Wraps the throwing portion of each
Exportfunction intry/catch, guarded by#if OPENTELEMETRY_HAVE_EXCEPTIONS(the project's standard guard for builds with exceptions disabled via-fno-exceptions). On exception, the error is logged viaOTEL_INTERNAL_LOG_ERRORandkFailureis returned.What the change does NOT do
noexceptspecifierkSuccesskFailurebefore the try block)std::terminate()(crash) to logging an error and returningkFailure(graceful degradation)For significant contributions please make sure you have completed the following items:
CHANGELOG.mdupdated for non-trivial changesAI
Assisted-by: This contribution was prepared with the assistance of an AI development tool.