Commit Graph
25 Commits
Author SHA1 Message Date
Magne Sjaastad c180247db2 Telemetry: Make isReportingCrash static to avoid creating the singleton in the event filter
RiaGuiApplication::notify queried RiaOpenTelemetryManager::instance() for every event. Make the crash flag a static atomic so the check never constructs the manager or takes part in its initialization.
2026-10-19 12:05:12 +02:00
Magne Sjaastad 4770abda8e Do not dispatch widget events while sending a crash report
Repainting while the crash handler pumps the event loop can crash again,
replacing the original report with one blaming the crash handler.

Call stack:
[0] performCrashLogging at ResInsight/ApplicationExeCode/RiaMainTools.cpp:178
[1] manageSegFailureSA(int, siginfo_t*, void*) at ResInsight/ApplicationExeCode/RiaMainTools.cpp:310
[21] RiaGuiApplication::notify(QObject*, QEvent*) at ResInsight/ApplicationLibCode/Application/RiaGuiApplication.cpp:1879
[30] RiaOpenTelemetryManager::reportCrash(int, std::basic_stacktrace<std::allocator<std::stacktrace_entry> > const&, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > const&) at ResInsight/ApplicationLibCode/Application/Tools/Telemetry/RiaOpenTelemetryManager.cpp:429
[31] performCrashLogging at ResInsight/ApplicationExeCode/RiaMainTools.cpp:211
[32] manageSegFailureSA(int, siginfo_t*, void*) at ResInsight/ApplicationExeCode/RiaMainTools.cpp:310
[52] RiaGuiApplication::notify(QObject*, QEvent*) at ResInsight/ApplicationLibCode/Application/RiaGuiApplication.cpp:1879
[62] main at ResInsight/ApplicationExeCode/RiaMain.cpp:267
[63] __libc_start_main at :0
2026-10-19 09:41:18 +02:00
magnesj 3f7aee5972 #14720 Probe std::stacktrace by linking instead of trusting the feature macro
libstdc++ defines __cpp_lib_stacktrace from GCC 13 on, but the implementation
lives in libstdc++exp, which some distributions do not ship (Red Hat's
gcc-toolset among them). The header-only feature test then reports the feature
as present and the link fails with undefined references to
std::__stacktrace_impl::_S_current.

Add cmake/StdStacktrace.cmake, which probes the feature by actually linking:
first with no extra library, then with stdc++exp. The result selects the link
library through RESINSIGHT_STACKTRACE_LIBRARIES, or defines
RIA_HAS_STD_STACKTRACE=0 project-wide when neither links, so the crash handler
compiles out its stack-trace capture and logs the signal only.

RiaMainTools.cpp and RiaOpenTelemetryManager.h now honour a
RIA_HAS_STD_STACKTRACE definition from the build system and only include
<stacktrace> when the feature is enabled.

Follow-up to #14045.
2026-09-10 08:33:38 -04:00
Magne Sjaastad e2319d0bd3 #14566 OpenTelemetry: stop unbounded log flood on send failures
Send one batched request per event batch instead of one request per event.
Application Insights v2/track accepts an array of envelopes, so a batch of up
to maxBatchSize (512) events was previously issued as 512 concurrent POSTs.
QNetworkAccessManager only opens a handful of connections per host, so the
queued requests were aborted by their own transfer timeout before reaching the
wire, reported as "HTTP 0: Operation canceled".

Honour the circuit breaker in processEvents(). It was only checked when
enqueuing, so the up to 10000 already queued events kept being posted at full
rate after the breaker opened. The crash and shutdown flush bypasses the
breaker so a crash report is still attempted.

Keep at most one request in flight. Failures are only observed when the reply
finishes, which for an unreachable endpoint takes the full transfer timeout,
and the 100 ms timer kept launching requests during that window.

Log the circuit breaker transition once instead of on every subsequent failure.

Only read the reply body when the device is open. An aborted reply has a closed
device, and reading from it emitted a QIODevice warning per request.

Call attemptReconnection() from the process timer. It was dead code, so once
the breaker opened it could only close if a reply happened to succeed.
2026-08-21 14:37:58 +02:00
Magne Sjaastad 94da54c4f5 Remove AsyncPdmObjectVectorDeleter and delete PDM objects synchronously
Deleting PDM objects on a worker thread is not safe. PdmObjectHandle::prepareForDelete()
mutates state owned by other objects, it nulls the guarded pointers held by other objects
and clears m_pointersReferencingMe, an unsynchronised std::set that every PdmPointer
construction and destruction touches. Destroying an object off the main thread therefore
races with the main thread on the shared object graph. See issue 14491.

Profiling a summary ensemble teardown shows the mechanism does not pay for itself. Releasing
397 Drogon realizations takes 0.24 s sequentially and 0.24 s in parallel, and for a heavy
case the parallel release is slower than the sequential one, because free() is serialised
inside the allocator. The PDM bookkeeping itself is 0.4 to 2.8 percent of the teardown.

Remove the class and deleteChildrenAsync(), and delete synchronously instead. The call sites
that used clearWithoutDelete() and a manual delete loop to work around the race can now call
deleteChildren() directly. Add caf::PdmObjectHandleTools::deleteObjects() for the case where
the objects are no longer owned by a child array field.

The observer disconnection from issue 12262 does not depend on clearWithoutDelete(). ~Signal()
unregisters itself from every observer, so a deleted child detaches itself. That fix addressed
the async race, where ~Signal() mutated the observer list from a worker thread. The unit test
is updated to assert the observed signal count directly instead of relying on a crash.
2026-08-10 09:40:33 +02:00
Kristian Bendiksen ac97f76e97 #14312 Exclude user input events while pumping the event loop during crash reporting
reportCrash pumps a nested Qt event loop from within the signal handler to
let the async crash-report HTTP POST finish. Pumping all events also
dispatches buffered mouse/keyboard events, which re-enter arbitrary UI code
mid-crash and can re-trigger the faulting path, causing a double-fault
inside the handler. Pump with QEventLoop::ExcludeUserInputEvents so socket
and timer events still flow (the reply completes) while user input is held
back.

Fixes #14312
2026-06-24 16:06:12 +02:00
Magne Sjaastad 022d77bef8 macOS: Initial Apple Silicon and x86_64 build support
* Refactor: add MACOSX_BUNDLE option to qt_add_executable in multiple CMakeLists.txt files
* #14045 macOS: Guard std::stacktrace usage and skip ucontext on Apple platforms
* #14045 macOS: Guard std::ispanstream with std::istringstream fallback
* #14045 macOS: Add vcpkg overlay triplets for osx and exclude grpc on osx
* #14045 macOS: CMake macOS build support and openzgy OpenMP-disable patch
* #14045 CI: Add macOS build workflow
* #14045 macOS: Use feature-test macros to detect <stacktrace> and <spanstream>
* #14045 macOS: Make MAX_STIMPLAN_LAYERS constexpr to fix arm64 link error
* #14045 CI: Ship README-macOS.txt with artifact to document Gatekeeper workaround
* #14045 CI: Pin macOS runner to macos-14 and set deployment target to 14.0
* #14045 CI: Move macOS runner to macos-15 and fix README step on configure failure
2026-06-01 12:38:55 +02:00
Magne Sjaastad 2cd036c988 #14054 Telemetry: Store SHA-256 hash of username instead of cleartext, send user.hash on crash reports 2026-05-26 15:59:24 +02:00
Kristian Bendiksen 5ffcb69acc #13126 RiaLogging: Use std::string_view instead of QString for logging 2026-05-08 10:11:09 +02:00
Magne Sjaastad 8df24c5bd3 Crash: use SA_SIGINFO on Linux for enhanced crash diagnostics
Switch signal handler registration from signal() to sigaction(SA_SIGINFO)
on Linux to capture fault address, signal code description, and program
counter at crash time. These are logged to the file logger and included
in OpenTelemetry crash reports.
2026-03-23 10:30:14 +01:00
Magne Sjaastad 1fdd493bfb #13728 Telemetry: Include OS info for all events
Add OS info (os.type, os.version, os.name) to all non-crash events in
reportEventAsync. Consolidate OS info and hashUsername into an anonymous
namespace with a shared addOsInfo helper function.
2026-03-11 12:46:32 +01:00
Magne Sjaastad c13eed4544 RiaOpenTelemetryManager: Ensure crash reports are sent before exit
- Track pending network replies using an atomic counter
- Pump the event loop in `reportCrash` to allow asynchronous telemetry requests to complete before the process terminates
- Use a timeout to prevent the crash handler from hanging indefinitely if the network is unresponsive
2026-03-09 15:34:39 +01:00
Magne Sjaastad 71e57f9beb Remove LoggingState enum from OpenTelemetry preferences
OpenTelemetry initialization is now driven by the presence of a config
file: if no config file is found (connection string is empty), init is
skipped silently without writing to the log.
2026-02-26 08:23:53 +01:00
magnesj 3d1abec870 Fixes by clang-tidy 2026-02-25 06:43:05 +01:00
magnesj fade1f61eb Fixes by clang-tidy 2026-02-24 06:49:16 +01:00
Magne Sjaastad 74324d14a4 Telemetry: Add event allowlist/denylist filtering
Extend opentelemetry_config.json with optional event_allowlist and
event_denylist arrays. Patterns support wildcard suffix (e.g. grpc.*).
Allowlist is checked first; denylist further restricts within the
allowed set. crash.* events always bypass all filters and queue limits.

Add RiaConnectorTools-Test.cpp covering all JSON value types including
the new array handling.
2026-02-23 12:29:41 +01:00
Magne Sjaastad d9c26c2c6d Improve cleanup and signal disconnection on teardown
Add explicit disconnection of signals and abort pending network replies in destructors and shutdown methods to prevent unwanted callbacks and threading issues during object destruction or shutdown. This enhances robustness and safety, especially in asynchronous and multi-threaded contexts.
2026-01-29 11:16:22 +01:00
magnesj 4966a179cb Fixes by clang-format 2026-01-20 13:44:06 +01:00
Magne Sjaastad 71a90a8cb9 Enhances telemetry data with user info
Adds username hashing for privacy-preserving telemetry and includes full username for crash reports to aid debugging.
Also incorporates OS information into crash reports for better diagnostics.
2026-01-20 13:44:06 +01:00
Magne 1e0ddc2b03 Fixes crash reporting for empty lines that might happen if limited debug info is available. 2026-01-05 13:26:54 +01:00
magnesj 937d9e0050 Fixes by clang-tidy 2025-12-23 08:19:11 +01:00
Magne Sjaastad 96eebdf8ef Enhances crash reporting for Application Insights
Refactors crash reporting to include structured stack trace data formatted as JSON for better integration with Application Insights.
2025-12-22 16:41:29 +01:00
Magne Sjaastad 7f0ef8dbc4 Simplifies OpenTelemetry integration
Removes conditional compilation for OpenTelemetry, ensuring it is always included.

Reinitializes OpenTelemetry based on user preferences, ensuring that changes to telemetry settings are applied immediately.

Configures cloud services, including OpenTelemetry, after the logger is initialized, ensuring that telemetry data is properly captured and transmitted.

Retrieves system username for telemetry tracking.
2025-12-22 16:41:29 +01:00
Magne Sjaastad 60081466a7 Improves stack trace readability.
Modifies the stack trace reporting to only include the path relative to the ResInsight root folder, enhancing readability and reducing verbosity in crash reports.
2025-12-18 08:40:30 +01:00
Magne Sjaastad 6c11e53f21 Adds OpenTelemetry integration
Adds support for OpenTelemetry to enable telemetry and crash reporting.

This change introduces:
- New RiaPreferencesOpenTelemetry class for managing OpenTelemetry configuration.
- RiaOpenTelemetryManager class for handling the OpenTelemetry lifecycle,
  event processing, and error handling.
- Configuration options in preferences to enable, disable, and configure
  OpenTelemetry.
- Asynchronous event reporting.
- Crash reporting capabilities.
- Health monitoring features.
2025-12-18 08:40:30 +01:00