From 2bd5723e31ff23d98aa35bab97612724c941b418 Mon Sep 17 00:00:00 2001 From: Bruno Garcia Date: Sun, 10 Nov 2024 12:51:35 -0500 Subject: [PATCH 01/13] Suppress EntryPointNotFoundException on sentry native --- package-dev/Runtime/SentryInitialization.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/package-dev/Runtime/SentryInitialization.cs b/package-dev/Runtime/SentryInitialization.cs index c786d8e96..c0559f9d0 100644 --- a/package-dev/Runtime/SentryInitialization.cs +++ b/package-dev/Runtime/SentryInitialization.cs @@ -123,10 +123,18 @@ public static void Init() [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] public static void ReinstallBackend() { - // At this point Unity has taken the signal handler and will not invoke our handler. So we register our - // backend once more to make sure user-defined data is available in the crash report and the SDK is able - // to capture the crash. - SentryNative.ReinstallBackend(); + try + { + // At this point Unity has taken the signal handler and will not invoke our handler. So we register our + // backend once more to make sure user-defined data is available in the crash report and the SDK is able + // to capture the crash. + SentryNative.ReinstallBackend(); + } + catch (EntryPointNotFoundException e) + { + // See: https://github.com/getsentry/sentry-unity/issues/1864 + // TODO: if option.Debug: true, debug log this + } } #endif } From 93b5e0fc5dde9de7a7d78c50f11731a27889bf92 Mon Sep 17 00:00:00 2001 From: Bruno Garcia Date: Sun, 10 Nov 2024 12:54:32 -0500 Subject: [PATCH 02/13] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d5c9829b..750e72f23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Fixes + +- Suppress EntryPointNotFoundException if sentry-native is not available at runtime. It'll continue to capture C# errors at least, but no native crashes. ([#1895](https://github.com/getsentry/sentry-unity/pull/1895)) + ### Dependencies - Bump .NET SDK from v4.12.1 to v4.13.0 ([#1879](https://github.com/getsentry/sentry-unity/pull/1879), [#1885](https://github.com/getsentry/sentry-unity/pull/1885)) From aee5507f1dc4dbd0f1fb81b0d8a3730b5b158899 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Mon, 11 Nov 2024 21:10:33 +0100 Subject: [PATCH 03/13] move backend reinstall --- package-dev/Runtime/SentryInitialization.cs | 19 ---------------- src/Sentry.Unity.Native/SentryNative.cs | 24 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/package-dev/Runtime/SentryInitialization.cs b/package-dev/Runtime/SentryInitialization.cs index c0559f9d0..4c821ef9e 100644 --- a/package-dev/Runtime/SentryInitialization.cs +++ b/package-dev/Runtime/SentryInitialization.cs @@ -118,25 +118,6 @@ public static void Init() #endif } } - -#if SENTRY_NATIVE - [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] - public static void ReinstallBackend() - { - try - { - // At this point Unity has taken the signal handler and will not invoke our handler. So we register our - // backend once more to make sure user-defined data is available in the crash report and the SDK is able - // to capture the crash. - SentryNative.ReinstallBackend(); - } - catch (EntryPointNotFoundException e) - { - // See: https://github.com/getsentry/sentry-unity/issues/1864 - // TODO: if option.Debug: true, debug log this - } - } -#endif } public class SentryUnityInfo : ISentryUnityInfo diff --git a/src/Sentry.Unity.Native/SentryNative.cs b/src/Sentry.Unity.Native/SentryNative.cs index 3fec6e556..50f4c12eb 100644 --- a/src/Sentry.Unity.Native/SentryNative.cs +++ b/src/Sentry.Unity.Native/SentryNative.cs @@ -2,6 +2,7 @@ using Sentry.Extensibility; using Sentry.Unity.Integrations; using System.Collections.Generic; +using UnityEngine; using UnityEngine.Analytics; namespace Sentry.Unity.Native; @@ -13,6 +14,8 @@ public static class SentryNative { private static readonly Dictionary PerDirectoryCrashInfo = new(); + private static Action? ReinstallBackendFunction; + /// /// Configures the native SDK. /// @@ -80,7 +83,26 @@ public static void Configure(SentryUnityOptions options, ISentryUnityInfo sentry } } options.CrashedLastRun = () => crashedLastRun; + + // The backend will only be reinstalled if the native SDK has been initialized successfully. + // We're handing this off to be called in `BeforeSceneLoad` instead of `SubsystemRegistration` as it's too soon + // and the SignalHandler would still get overwritten. + ReinstallBackendFunction = SentryNativeBridge.ReinstallBackend; } - public static void ReinstallBackend() => SentryNativeBridge.ReinstallBackend(); + [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] + public static void ReinstallBackend() + { + try + { + // At this point Unity has taken the signal handler and will not invoke our handler. So we register our + // backend once more to make sure user-defined data is available in the crash report and the SDK is able + // to capture the crash. + ReinstallBackendFunction?.Invoke(); + } + catch (EntryPointNotFoundException e) + { + SentrySdk.CaptureException(new Exception("The SDK failed to reinstall the backend and won't capture native errors.", e)); + } + } } From 66c8869a0b7759d95dfc3a4e3e7a7ff127ab6603 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Mon, 11 Nov 2024 21:14:51 +0100 Subject: [PATCH 04/13] catch them all --- src/Sentry.Unity.Native/SentryNative.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sentry.Unity.Native/SentryNative.cs b/src/Sentry.Unity.Native/SentryNative.cs index 50f4c12eb..2e527207b 100644 --- a/src/Sentry.Unity.Native/SentryNative.cs +++ b/src/Sentry.Unity.Native/SentryNative.cs @@ -100,7 +100,7 @@ public static void ReinstallBackend() // to capture the crash. ReinstallBackendFunction?.Invoke(); } - catch (EntryPointNotFoundException e) + catch (Exception e) { SentrySdk.CaptureException(new Exception("The SDK failed to reinstall the backend and won't capture native errors.", e)); } From e43b3d1fae46639567a96acd7a273e832f6d482a Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Mon, 11 Nov 2024 23:50:56 +0100 Subject: [PATCH 05/13] cleanup --- src/Sentry.Unity.Native/SentryNative.cs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Sentry.Unity.Native/SentryNative.cs b/src/Sentry.Unity.Native/SentryNative.cs index 2e527207b..4a79e7aca 100644 --- a/src/Sentry.Unity.Native/SentryNative.cs +++ b/src/Sentry.Unity.Native/SentryNative.cs @@ -14,7 +14,7 @@ public static class SentryNative { private static readonly Dictionary PerDirectoryCrashInfo = new(); - private static Action? ReinstallBackendFunction; + private static bool ShouldReinstallBackend; /// /// Configures the native SDK. @@ -84,23 +84,28 @@ public static void Configure(SentryUnityOptions options, ISentryUnityInfo sentry } options.CrashedLastRun = () => crashedLastRun; - // The backend will only be reinstalled if the native SDK has been initialized successfully. - // We're handing this off to be called in `BeforeSceneLoad` instead of `SubsystemRegistration` as it's too soon - // and the SignalHandler would still get overwritten. - ReinstallBackendFunction = SentryNativeBridge.ReinstallBackend; + ShouldReinstallBackend = true; } + // We're calling this in `BeforeSceneLoad` instead of `SubsystemRegistration` as it's too soon and the + // SignalHandler would still get overwritten. [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] - public static void ReinstallBackend() + private static void ReinstallBackend() { + // The backend should only be reinstalled if the native SDK has been initialized successfully. + if (!ShouldReinstallBackend) + { + return; + } + try { // At this point Unity has taken the signal handler and will not invoke our handler. So we register our // backend once more to make sure user-defined data is available in the crash report and the SDK is able // to capture the crash. - ReinstallBackendFunction?.Invoke(); + SentryNativeBridge.ReinstallBackend(); } - catch (Exception e) + catch (EntryPointNotFoundException e) { SentrySdk.CaptureException(new Exception("The SDK failed to reinstall the backend and won't capture native errors.", e)); } From 7f2633c6637a3badb67d1e00e5377156b9f5006a Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Tue, 12 Nov 2024 17:43:14 +0100 Subject: [PATCH 06/13] logging --- src/Sentry.Unity.Native/SentryNative.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Sentry.Unity.Native/SentryNative.cs b/src/Sentry.Unity.Native/SentryNative.cs index 4a79e7aca..820610e92 100644 --- a/src/Sentry.Unity.Native/SentryNative.cs +++ b/src/Sentry.Unity.Native/SentryNative.cs @@ -15,6 +15,7 @@ public static class SentryNative private static readonly Dictionary PerDirectoryCrashInfo = new(); private static bool ShouldReinstallBackend; + private static IDiagnosticLogger? _logger; /// /// Configures the native SDK. @@ -23,11 +24,13 @@ public static class SentryNative /// Infos about the current Unity environment public static void Configure(SentryUnityOptions options, ISentryUnityInfo sentryUnityInfo) { - options.DiagnosticLogger?.LogInfo("Attempting to configure native support via the Native SDK"); + _logger = options.DiagnosticLogger; + + _logger?.LogInfo("Attempting to configure native support via the Native SDK"); if (!sentryUnityInfo.IsNativeSupportEnabled(options, ApplicationAdapter.Instance.Platform)) { - options.DiagnosticLogger?.LogDebug("Native support is disabled for '{0}'.", ApplicationAdapter.Instance.Platform); + _logger?.LogDebug("Native support is disabled for '{0}'.", ApplicationAdapter.Instance.Platform); return; } @@ -35,21 +38,21 @@ public static void Configure(SentryUnityOptions options, ISentryUnityInfo sentry { if (!SentryNativeBridge.Init(options, sentryUnityInfo)) { - options.DiagnosticLogger? + _logger? .LogWarning("Sentry native initialization failed - native crashes are not captured."); return; } } catch (Exception e) { - options.DiagnosticLogger? + _logger? .LogError(e, "Sentry native initialization failed - native crashes are not captured."); return; } ApplicationAdapter.Instance.Quitting += () => { - options.DiagnosticLogger?.LogDebug("Closing the sentry-native SDK"); + _logger?.LogDebug("Closing the sentry-native SDK"); SentryNativeBridge.Close(); }; options.ScopeObserver = new NativeScopeObserver(options); @@ -78,7 +81,7 @@ public static void Configure(SentryUnityOptions options, ISentryUnityInfo sentry crashedLastRun = SentryNativeBridge.HandleCrashedLastRun(options); PerDirectoryCrashInfo.Add(cacheDirectory, crashedLastRun); - options.DiagnosticLogger? + _logger? .LogDebug("Native SDK reported: 'crashedLastRun': '{0}'", crashedLastRun); } } @@ -95,6 +98,7 @@ private static void ReinstallBackend() // The backend should only be reinstalled if the native SDK has been initialized successfully. if (!ShouldReinstallBackend) { + _logger?.LogDebug("Skipping reinstalling the native backend as the initialization seems to have failed."); return; } @@ -107,7 +111,7 @@ private static void ReinstallBackend() } catch (EntryPointNotFoundException e) { - SentrySdk.CaptureException(new Exception("The SDK failed to reinstall the backend and won't capture native errors.", e)); + _logger?.LogError(e, "The SDK failed to reinstall the backend - native crashes are not captured."); } } } From a9712c3cf633b44666c1236b92a291a92786df33 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Tue, 12 Nov 2024 17:45:19 +0100 Subject: [PATCH 07/13] log instead of capture --- package-dev/Runtime/SentryInitialization.cs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/package-dev/Runtime/SentryInitialization.cs b/package-dev/Runtime/SentryInitialization.cs index 4c821ef9e..ab8f4c334 100644 --- a/package-dev/Runtime/SentryInitialization.cs +++ b/package-dev/Runtime/SentryInitialization.cs @@ -60,7 +60,6 @@ public static void Init() if (options != null && options.ShouldInitializeSdk()) { SentryIntegrations.Configure(options); - Exception nativeInitException = null; try { @@ -76,20 +75,16 @@ public static void Init() } catch (DllNotFoundException e) { - nativeInitException = new Exception( + options.DiagnosticLogger?.LogError( "Sentry native-error capture configuration failed to load a native library. This usually " + "means the library is missing from the application bundle or the installation directory.", e); } catch (Exception e) { - nativeInitException = new Exception("Sentry native error capture configuration failed.", e); + options.DiagnosticLogger?.LogError("Sentry native error capture configuration failed.", e); } SentryUnity.Init(options); - if (nativeInitException != null) - { - SentrySdk.CaptureException(nativeInitException); - } #if !SENTRY_WEBGL if (options.TracesSampleRate > 0.0f && options.AutoStartupTraces) From a4fafb47fb49e7ac83f0732e3d6f289d14ab4642 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Tue, 12 Nov 2024 17:47:28 +0100 Subject: [PATCH 08/13] style --- src/Sentry.Unity.Native/SentryNative.cs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Sentry.Unity.Native/SentryNative.cs b/src/Sentry.Unity.Native/SentryNative.cs index 820610e92..18d54255e 100644 --- a/src/Sentry.Unity.Native/SentryNative.cs +++ b/src/Sentry.Unity.Native/SentryNative.cs @@ -15,7 +15,7 @@ public static class SentryNative private static readonly Dictionary PerDirectoryCrashInfo = new(); private static bool ShouldReinstallBackend; - private static IDiagnosticLogger? _logger; + private static IDiagnosticLogger? Logger; /// /// Configures the native SDK. @@ -24,13 +24,13 @@ public static class SentryNative /// Infos about the current Unity environment public static void Configure(SentryUnityOptions options, ISentryUnityInfo sentryUnityInfo) { - _logger = options.DiagnosticLogger; + Logger = options.DiagnosticLogger; - _logger?.LogInfo("Attempting to configure native support via the Native SDK"); + Logger?.LogInfo("Attempting to configure native support via the Native SDK"); if (!sentryUnityInfo.IsNativeSupportEnabled(options, ApplicationAdapter.Instance.Platform)) { - _logger?.LogDebug("Native support is disabled for '{0}'.", ApplicationAdapter.Instance.Platform); + Logger?.LogDebug("Native support is disabled for '{0}'.", ApplicationAdapter.Instance.Platform); return; } @@ -38,21 +38,21 @@ public static void Configure(SentryUnityOptions options, ISentryUnityInfo sentry { if (!SentryNativeBridge.Init(options, sentryUnityInfo)) { - _logger? + Logger? .LogWarning("Sentry native initialization failed - native crashes are not captured."); return; } } catch (Exception e) { - _logger? + Logger? .LogError(e, "Sentry native initialization failed - native crashes are not captured."); return; } ApplicationAdapter.Instance.Quitting += () => { - _logger?.LogDebug("Closing the sentry-native SDK"); + Logger?.LogDebug("Closing the sentry-native SDK"); SentryNativeBridge.Close(); }; options.ScopeObserver = new NativeScopeObserver(options); @@ -81,7 +81,7 @@ public static void Configure(SentryUnityOptions options, ISentryUnityInfo sentry crashedLastRun = SentryNativeBridge.HandleCrashedLastRun(options); PerDirectoryCrashInfo.Add(cacheDirectory, crashedLastRun); - _logger? + Logger? .LogDebug("Native SDK reported: 'crashedLastRun': '{0}'", crashedLastRun); } } @@ -98,7 +98,7 @@ private static void ReinstallBackend() // The backend should only be reinstalled if the native SDK has been initialized successfully. if (!ShouldReinstallBackend) { - _logger?.LogDebug("Skipping reinstalling the native backend as the initialization seems to have failed."); + Logger?.LogDebug("Skipping reinstalling the native backend as the initialization seems to have failed."); return; } @@ -111,7 +111,7 @@ private static void ReinstallBackend() } catch (EntryPointNotFoundException e) { - _logger?.LogError(e, "The SDK failed to reinstall the backend - native crashes are not captured."); + Logger?.LogError(e, "The SDK failed to reinstall the backend - native crashes are not captured."); } } } From d5d3f613a9c556b848b6d90509b6e4a7fde62700 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Tue, 12 Nov 2024 17:56:58 +0100 Subject: [PATCH 09/13] Updated CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 750e72f23..6dc848cc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Fixes -- Suppress EntryPointNotFoundException if sentry-native is not available at runtime. It'll continue to capture C# errors at least, but no native crashes. ([#1895](https://github.com/getsentry/sentry-unity/pull/1895)) +- Suppress EntryPointNotFoundException if sentry-native is not available at runtime. It'll continue to capture C# errors at least, but no native crashes. ([#1898](https://github.com/getsentry/sentry-unity/pull/1898)) ### Dependencies From ec6f6c58ffa9f5d813f2d87d12e9a89cd8f8f462 Mon Sep 17 00:00:00 2001 From: Stefan Jandl Date: Wed, 13 Nov 2024 12:17:12 +0100 Subject: [PATCH 10/13] Update src/Sentry.Unity.Native/SentryNative.cs Co-authored-by: Bruno Garcia --- src/Sentry.Unity.Native/SentryNative.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sentry.Unity.Native/SentryNative.cs b/src/Sentry.Unity.Native/SentryNative.cs index 18d54255e..792e8dee7 100644 --- a/src/Sentry.Unity.Native/SentryNative.cs +++ b/src/Sentry.Unity.Native/SentryNative.cs @@ -111,7 +111,7 @@ private static void ReinstallBackend() } catch (EntryPointNotFoundException e) { - Logger?.LogError(e, "The SDK failed to reinstall the backend - native crashes are not captured."); + Logger?.LogError(e, "Native dependency not found. Did you delete sentry.dll or move files around?"); } } } From c965fdd407274e68115ccac7e8dcc3a8b88aceed Mon Sep 17 00:00:00 2001 From: Stefan Jandl Date: Wed, 13 Nov 2024 12:17:24 +0100 Subject: [PATCH 11/13] Update src/Sentry.Unity.Native/SentryNative.cs Co-authored-by: Bruno Garcia --- src/Sentry.Unity.Native/SentryNative.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sentry.Unity.Native/SentryNative.cs b/src/Sentry.Unity.Native/SentryNative.cs index 792e8dee7..b0152e05a 100644 --- a/src/Sentry.Unity.Native/SentryNative.cs +++ b/src/Sentry.Unity.Native/SentryNative.cs @@ -98,7 +98,7 @@ private static void ReinstallBackend() // The backend should only be reinstalled if the native SDK has been initialized successfully. if (!ShouldReinstallBackend) { - Logger?.LogDebug("Skipping reinstalling the native backend as the initialization seems to have failed."); + Logger?.LogWarning("Skipping reinstalling the native backend."); return; } From e5fcce47005494dee5e5c7137caa6db835dd9f66 Mon Sep 17 00:00:00 2001 From: Stefan Jandl Date: Wed, 13 Nov 2024 12:17:38 +0100 Subject: [PATCH 12/13] Update src/Sentry.Unity.Native/SentryNative.cs Co-authored-by: Bruno Garcia --- src/Sentry.Unity.Native/SentryNative.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Sentry.Unity.Native/SentryNative.cs b/src/Sentry.Unity.Native/SentryNative.cs index b0152e05a..7525cb42c 100644 --- a/src/Sentry.Unity.Native/SentryNative.cs +++ b/src/Sentry.Unity.Native/SentryNative.cs @@ -100,6 +100,8 @@ private static void ReinstallBackend() { Logger?.LogWarning("Skipping reinstalling the native backend."); return; + } else { + Logger?.LogDebug("Reinstalling the native backend to make sure we capture native crashes."); } try From f96728ac3a27dbc0b12bf93d725ce51a7cf7671c Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Wed, 13 Nov 2024 11:23:11 +0000 Subject: [PATCH 13/13] Format code --- src/Sentry.Unity.Native/SentryNative.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Sentry.Unity.Native/SentryNative.cs b/src/Sentry.Unity.Native/SentryNative.cs index 7525cb42c..94d1227ab 100644 --- a/src/Sentry.Unity.Native/SentryNative.cs +++ b/src/Sentry.Unity.Native/SentryNative.cs @@ -100,7 +100,9 @@ private static void ReinstallBackend() { Logger?.LogWarning("Skipping reinstalling the native backend."); return; - } else { + } + else + { Logger?.LogDebug("Reinstalling the native backend to make sure we capture native crashes."); }