From 7524563f4391fe33291e6ddc632c902af02e002a Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Fri, 13 Oct 2023 14:11:46 +0200 Subject: [PATCH 01/12] known platform check --- src/Sentry.Unity.iOS/SentryNativeCocoa.cs | 2 +- src/Sentry.Unity/ISentryUnityInfo.cs | 2 ++ .../ScriptableSentryUnityOptions.cs | 31 ++++++------------- .../SentryNativeAndroidTests.cs | 1 + .../SentryNativeIosTests.cs | 1 + 5 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/Sentry.Unity.iOS/SentryNativeCocoa.cs b/src/Sentry.Unity.iOS/SentryNativeCocoa.cs index 8b8fb31fa..497b70c0c 100644 --- a/src/Sentry.Unity.iOS/SentryNativeCocoa.cs +++ b/src/Sentry.Unity.iOS/SentryNativeCocoa.cs @@ -27,7 +27,7 @@ internal static void Configure(SentryUnityOptions options, ISentryUnityInfo sent } options.ScopeObserver = new NativeScopeObserver("iOS", options); break; - case RuntimePlatform.OSXPlayer: + case RuntimePlatform.OSXPlayer or RuntimePlatform.OSXServer: if (!options.MacosNativeSupportEnabled) { return; diff --git a/src/Sentry.Unity/ISentryUnityInfo.cs b/src/Sentry.Unity/ISentryUnityInfo.cs index 8a44c124e..bfc818a8a 100644 --- a/src/Sentry.Unity/ISentryUnityInfo.cs +++ b/src/Sentry.Unity/ISentryUnityInfo.cs @@ -1,4 +1,5 @@ using System; +using Sentry.Unity.Integrations; namespace Sentry.Unity { @@ -6,6 +7,7 @@ public interface ISentryUnityInfo { public bool IL2CPP { get; } public Il2CppMethods? Il2CppMethods { get; } + public bool IsKnownPlatform(); } public class Il2CppMethods diff --git a/src/Sentry.Unity/ScriptableSentryUnityOptions.cs b/src/Sentry.Unity/ScriptableSentryUnityOptions.cs index 991bb7f6d..6ec5ff84e 100644 --- a/src/Sentry.Unity/ScriptableSentryUnityOptions.cs +++ b/src/Sentry.Unity/ScriptableSentryUnityOptions.cs @@ -191,10 +191,15 @@ internal SentryUnityOptions ToSentryUnityOptions(bool isBuilding, ISentryUnityIn options.SetupLogging(); - // This has to happen in between options object creation and updating the options based on programmatic changes - if (!isBuilding && RuntimeOptionsConfiguration != null) + if (!isBuilding) { - RuntimeOptionsConfiguration.Configure(options); + if (RuntimeOptionsConfiguration != null) + { + // This has to happen in between options object creation and updating the options based on programmatic changes + RuntimeOptionsConfiguration.Configure(options); + } + + HandlePlatformRestrictions(options, application, unityInfo); } if (!application.IsEditor && options.Il2CppLineNumberSupportEnabled && unityInfo is not null) @@ -202,7 +207,6 @@ internal SentryUnityOptions ToSentryUnityOptions(bool isBuilding, ISentryUnityIn options.AddIl2CppExceptionProcessor(unityInfo); } - HandlePlatformRestrictions(options, application); HandleExceptionFilter(options); if (!AnrDetectionEnabled) @@ -213,9 +217,9 @@ internal SentryUnityOptions ToSentryUnityOptions(bool isBuilding, ISentryUnityIn return options; } - private void HandlePlatformRestrictions(SentryUnityOptions options, IApplication application) + private void HandlePlatformRestrictions(SentryUnityOptions options, IApplication application, ISentryUnityInfo? unityInfo) { - if (IsKnownPlatform(application)) + if (unityInfo?.IsKnownPlatform() == true) { options.CacheDirectoryPath = EnableOfflineCaching ? application.PersistentDataPath : null; } @@ -270,20 +274,5 @@ internal bool ShouldDebug(bool isEditorPlayer) return Debug; } - - internal bool IsKnownPlatform(IApplication? application = null) - { - application ??= ApplicationAdapter.Instance; - return application.Platform - is RuntimePlatform.Android - or RuntimePlatform.IPhonePlayer - or RuntimePlatform.WindowsEditor - or RuntimePlatform.WindowsPlayer - or RuntimePlatform.OSXEditor - or RuntimePlatform.OSXPlayer - or RuntimePlatform.LinuxEditor - or RuntimePlatform.LinuxPlayer - or RuntimePlatform.WebGLPlayer; - } } } diff --git a/test/Sentry.Unity.Android.Tests/SentryNativeAndroidTests.cs b/test/Sentry.Unity.Android.Tests/SentryNativeAndroidTests.cs index cb41d567b..54f3d6d73 100644 --- a/test/Sentry.Unity.Android.Tests/SentryNativeAndroidTests.cs +++ b/test/Sentry.Unity.Android.Tests/SentryNativeAndroidTests.cs @@ -98,5 +98,6 @@ public class TestSentryUnityInfo : ISentryUnityInfo public bool IL2CPP { get; set; } public string? Platform { get; } public Il2CppMethods? Il2CppMethods { get; } + public bool IsKnownPlatform() => true; } } diff --git a/test/Sentry.Unity.iOS.Tests/SentryNativeIosTests.cs b/test/Sentry.Unity.iOS.Tests/SentryNativeIosTests.cs index c4809f11b..2fff04518 100644 --- a/test/Sentry.Unity.iOS.Tests/SentryNativeIosTests.cs +++ b/test/Sentry.Unity.iOS.Tests/SentryNativeIosTests.cs @@ -9,6 +9,7 @@ public class TestSentryUnityInfo : ISentryUnityInfo public bool IL2CPP { get; set; } public string? Platform { get; } public Il2CppMethods? Il2CppMethods { get; } + public bool IsKnownPlatform() => true; } public class SentryNativeCocoaTests From b8d9361c9a1e0769df9a1296fe5901c6a7d6fc1d Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Thu, 19 Oct 2023 18:03:58 +0200 Subject: [PATCH 02/12] conditionalize the enum --- package-dev/Runtime/SentryInitialization.cs | 20 ++++++++++++++++++++ src/Sentry.Unity.iOS/SentryNativeCocoa.cs | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/package-dev/Runtime/SentryInitialization.cs b/package-dev/Runtime/SentryInitialization.cs index e2d3406f5..029ad8933 100644 --- a/package-dev/Runtime/SentryInitialization.cs +++ b/package-dev/Runtime/SentryInitialization.cs @@ -269,5 +269,25 @@ private static void Il2CppNativeStackTraceShim(IntPtr exc, out IntPtr addresses, #endif #pragma warning restore 8632 #endif + + public bool IsKnownPlatform() + { + return Application.platform + is RuntimePlatform.Android + or RuntimePlatform.IPhonePlayer + or RuntimePlatform.WindowsEditor + or RuntimePlatform.WindowsPlayer + or RuntimePlatform.OSXEditor + or RuntimePlatform.OSXPlayer + or RuntimePlatform.LinuxEditor + or RuntimePlatform.LinuxPlayer + or RuntimePlatform.WebGLPlayer +#if UNITY_2021_3_OR_NEWER + or RuntimePlatform.LinuxServer + or RuntimePlatform.WindowsServer + or RuntimePlatform.OSXServer +#endif + ; + } } } diff --git a/src/Sentry.Unity.iOS/SentryNativeCocoa.cs b/src/Sentry.Unity.iOS/SentryNativeCocoa.cs index 497b70c0c..8b8fb31fa 100644 --- a/src/Sentry.Unity.iOS/SentryNativeCocoa.cs +++ b/src/Sentry.Unity.iOS/SentryNativeCocoa.cs @@ -27,7 +27,7 @@ internal static void Configure(SentryUnityOptions options, ISentryUnityInfo sent } options.ScopeObserver = new NativeScopeObserver("iOS", options); break; - case RuntimePlatform.OSXPlayer or RuntimePlatform.OSXServer: + case RuntimePlatform.OSXPlayer: if (!options.MacosNativeSupportEnabled) { return; From 15bfc0e2e9032eed619b31af7c3e533bdbbeb8a5 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Thu, 19 Oct 2023 18:10:33 +0200 Subject: [PATCH 03/12] Updated CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 252452a15..dc59c2fe3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +## Fixes + +- Added the dedicated server platforms to the known platforms to prevent the SDK from interpreting them as restricted platforms (i.e. disabling offline caching, session tracking) ([#1468](https://github.com/getsentry/sentry-unity/pull/1468)) + ### Dependencies - Bump CLI from v2.21.1 to v2.21.2 ([#1454](https://github.com/getsentry/sentry-unity/pull/1454)) From 84f1fc940f48873be2f14e3fca39dca704dee434 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Fri, 20 Oct 2023 11:16:31 +0200 Subject: [PATCH 04/12] backwards compatible means no C#9 --- package-dev/Runtime/SentryInitialization.cs | 27 +++++++++++---------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/package-dev/Runtime/SentryInitialization.cs b/package-dev/Runtime/SentryInitialization.cs index 029ad8933..cf654836a 100644 --- a/package-dev/Runtime/SentryInitialization.cs +++ b/package-dev/Runtime/SentryInitialization.cs @@ -272,20 +272,21 @@ private static void Il2CppNativeStackTraceShim(IntPtr exc, out IntPtr addresses, public bool IsKnownPlatform() { - return Application.platform - is RuntimePlatform.Android - or RuntimePlatform.IPhonePlayer - or RuntimePlatform.WindowsEditor - or RuntimePlatform.WindowsPlayer - or RuntimePlatform.OSXEditor - or RuntimePlatform.OSXPlayer - or RuntimePlatform.LinuxEditor - or RuntimePlatform.LinuxPlayer - or RuntimePlatform.WebGLPlayer + var platform = Application.platform; + return platform == RuntimePlatform.Android || + platform == RuntimePlatform.IPhonePlayer || + platform == RuntimePlatform.WindowsEditor || + platform == RuntimePlatform.WindowsPlayer || + platform == RuntimePlatform.OSXEditor || + platform == RuntimePlatform.OSXPlayer || + platform == RuntimePlatform.LinuxEditor || + platform == RuntimePlatform.LinuxPlayer || + platform == RuntimePlatform.WebGLPlayer #if UNITY_2021_3_OR_NEWER - or RuntimePlatform.LinuxServer - or RuntimePlatform.WindowsServer - or RuntimePlatform.OSXServer + || + platform == RuntimePlatform.LinuxServer || + platform == RuntimePlatform.WindowsServer || + platform == RuntimePlatform.OSXServer #endif ; } From 692dd6a73a1c0042834132759c986d35e1ab2dc4 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Wed, 25 Oct 2023 17:29:26 +0200 Subject: [PATCH 05/12] native support --- src/Sentry.Unity.Native/SentryNative.cs | 85 +++++++++---------- src/Sentry.Unity.iOS/SentryNativeCocoa.cs | 42 +++++---- src/Sentry.Unity/ISentryUnityInfo.cs | 3 +- .../SentryNativeAndroidTests.cs | 4 +- .../SentryNativeIosTests.cs | 3 +- 5 files changed, 68 insertions(+), 69 deletions(-) diff --git a/src/Sentry.Unity.Native/SentryNative.cs b/src/Sentry.Unity.Native/SentryNative.cs index e97b5841c..ef1e7af76 100644 --- a/src/Sentry.Unity.Native/SentryNative.cs +++ b/src/Sentry.Unity.Native/SentryNative.cs @@ -17,59 +17,58 @@ public static class SentryNative /// Configures the native SDK. /// /// The Sentry Unity options to use. - public static void Configure(SentryUnityOptions options) + /// Infos about the current Unity environment + public static void Configure(SentryUnityOptions options, ISentryUnityInfo sentryUnityInfo) { - if (ApplicationAdapter.Instance.Platform switch + if (!sentryUnityInfo.IsNativeSupportEnabled(options, ApplicationAdapter.Instance.Platform)) { - RuntimePlatform.WindowsPlayer => options.WindowsNativeSupportEnabled, - RuntimePlatform.LinuxPlayer => options.LinuxNativeSupportEnabled, - _ => false, - }) + options.DiagnosticLogger?.LogDebug("Native support is disabled for '{0}'.", ApplicationAdapter.Instance.Platform); + return; + } + + if (!SentryNativeBridge.Init(options)) { - if (!SentryNativeBridge.Init(options)) - { - options.DiagnosticLogger? - .LogWarning("Sentry native initialization failed - native crashes are not captured."); - return; - } + options.DiagnosticLogger? + .LogWarning("Sentry native initialization failed - native crashes are not captured."); + return; + } - ApplicationAdapter.Instance.Quitting += () => - { - options.DiagnosticLogger?.LogDebug("Closing the sentry-native SDK"); - SentryNativeBridge.Close(); - }; - options.ScopeObserver = new NativeScopeObserver(options); - options.EnableScopeSync = true; - options.NativeContextWriter = new NativeContextWriter(); + ApplicationAdapter.Instance.Quitting += () => + { + options.DiagnosticLogger?.LogDebug("Closing the sentry-native SDK"); + SentryNativeBridge.Close(); + }; + options.ScopeObserver = new NativeScopeObserver(options); + options.EnableScopeSync = true; + options.NativeContextWriter = new NativeContextWriter(); - // Use AnalyticsSessionInfo.userId as the default UserID in native & dotnet - options.DefaultUserId = AnalyticsSessionInfo.userId; - if (options.DefaultUserId is not null) - { - options.ScopeObserver.SetUser(new User { Id = options.DefaultUserId }); - } + // Use AnalyticsSessionInfo.userId as the default UserID in native & dotnet + options.DefaultUserId = AnalyticsSessionInfo.userId; + if (options.DefaultUserId is not null) + { + options.ScopeObserver.SetUser(new User { Id = options.DefaultUserId }); + } - // Note: we must actually call the function now and on every other call use the value we get here. - // Additionally, we cannot call this multiple times for the same directory, because the result changes - // on subsequent runs. Therefore, we cache the value during the whole runtime of the application. - var cacheDirectory = SentryNativeBridge.GetCacheDirectory(options); - var crashedLastRun = false; - // In the event the SDK is re-initialized with a different path on disk, we need to track which ones were already read - // Similarly we need to cache the value of each call since a subsequent call would return a different value - // as the file used on disk to mark it as crashed is deleted after we read it. - lock (PerDirectoryCrashInfo) + // Note: we must actually call the function now and on every other call use the value we get here. + // Additionally, we cannot call this multiple times for the same directory, because the result changes + // on subsequent runs. Therefore, we cache the value during the whole runtime of the application. + var cacheDirectory = SentryNativeBridge.GetCacheDirectory(options); + var crashedLastRun = false; + // In the event the SDK is re-initialized with a different path on disk, we need to track which ones were already read + // Similarly we need to cache the value of each call since a subsequent call would return a different value + // as the file used on disk to mark it as crashed is deleted after we read it. + lock (PerDirectoryCrashInfo) + { + if (!PerDirectoryCrashInfo.TryGetValue(cacheDirectory, out crashedLastRun)) { - if (!PerDirectoryCrashInfo.TryGetValue(cacheDirectory, out crashedLastRun)) - { - crashedLastRun = SentryNativeBridge.HandleCrashedLastRun(options); - PerDirectoryCrashInfo.Add(cacheDirectory, crashedLastRun); + crashedLastRun = SentryNativeBridge.HandleCrashedLastRun(options); + PerDirectoryCrashInfo.Add(cacheDirectory, crashedLastRun); - options.DiagnosticLogger? - .LogDebug("Native SDK reported: 'crashedLastRun': '{0}'", crashedLastRun); - } + options.DiagnosticLogger? + .LogDebug("Native SDK reported: 'crashedLastRun': '{0}'", crashedLastRun); } - options.CrashedLastRun = () => crashedLastRun; } + options.CrashedLastRun = () => crashedLastRun; } } } diff --git a/src/Sentry.Unity.iOS/SentryNativeCocoa.cs b/src/Sentry.Unity.iOS/SentryNativeCocoa.cs index 8b8fb31fa..fe234a536 100644 --- a/src/Sentry.Unity.iOS/SentryNativeCocoa.cs +++ b/src/Sentry.Unity.iOS/SentryNativeCocoa.cs @@ -1,4 +1,6 @@ +using System; using Sentry.Extensibility; +using Sentry.PlatformAbstractions; using Sentry.Unity.Integrations; using UnityEngine; @@ -13,36 +15,30 @@ public static class SentryNativeCocoa /// Configures the native support. /// /// The Sentry Unity options to use. + /// Infos about the current Unity environment public static void Configure(SentryUnityOptions options, ISentryUnityInfo sentryUnityInfo) => Configure(options, sentryUnityInfo, ApplicationAdapter.Instance.Platform); internal static void Configure(SentryUnityOptions options, ISentryUnityInfo sentryUnityInfo, RuntimePlatform platform) { - switch (platform) + if (!sentryUnityInfo.IsNativeSupportEnabled(options, platform)) { - case RuntimePlatform.IPhonePlayer: - if (!options.IosNativeSupportEnabled) - { - return; - } - options.ScopeObserver = new NativeScopeObserver("iOS", options); - break; - case RuntimePlatform.OSXPlayer: - if (!options.MacosNativeSupportEnabled) - { - return; - } - if (!SentryCocoaBridgeProxy.Init(options)) - { - options.DiagnosticLogger?.LogWarning("Failed to initialize the native SDK"); - return; - } - options.ScopeObserver = new NativeScopeObserver("macOS", options); - break; - default: - options.DiagnosticLogger? - .LogWarning("Cocoa SentryNative.Configure() called for unsupported platform: '{0}'", platform); + options.DiagnosticLogger?.LogDebug("Native support is not enabled for: '{0}'", platform); + return; + } + + if (platform == RuntimePlatform.IPhonePlayer) + { + options.ScopeObserver = new NativeScopeObserver("iOS", options); + } + else + { + if (!SentryCocoaBridgeProxy.Init(options)) + { + options.DiagnosticLogger?.LogWarning("Failed to initialize the native SDK"); return; + } + options.ScopeObserver = new NativeScopeObserver("macOS", options); } options.NativeContextWriter = new NativeContextWriter(); diff --git a/src/Sentry.Unity/ISentryUnityInfo.cs b/src/Sentry.Unity/ISentryUnityInfo.cs index bfc818a8a..b66d88c9e 100644 --- a/src/Sentry.Unity/ISentryUnityInfo.cs +++ b/src/Sentry.Unity/ISentryUnityInfo.cs @@ -1,5 +1,5 @@ using System; -using Sentry.Unity.Integrations; +using UnityEngine; namespace Sentry.Unity { @@ -8,6 +8,7 @@ public interface ISentryUnityInfo public bool IL2CPP { get; } public Il2CppMethods? Il2CppMethods { get; } public bool IsKnownPlatform(); + public bool IsNativeSupportEnabled(SentryUnityOptions options, RuntimePlatform platform); } public class Il2CppMethods diff --git a/test/Sentry.Unity.Android.Tests/SentryNativeAndroidTests.cs b/test/Sentry.Unity.Android.Tests/SentryNativeAndroidTests.cs index 54f3d6d73..d6ad6e0db 100644 --- a/test/Sentry.Unity.Android.Tests/SentryNativeAndroidTests.cs +++ b/test/Sentry.Unity.Android.Tests/SentryNativeAndroidTests.cs @@ -2,6 +2,7 @@ using System.Threading; using NUnit.Framework; using Sentry.Unity; +using UnityEngine; namespace Sentry.Unity.Android.Tests { @@ -98,6 +99,7 @@ public class TestSentryUnityInfo : ISentryUnityInfo public bool IL2CPP { get; set; } public string? Platform { get; } public Il2CppMethods? Il2CppMethods { get; } - public bool IsKnownPlatform() => true; + public bool IsKnownPlatform() => throw new NotImplementedException(); + public bool IsNativeSupportEnabled(SentryUnityOptions options, RuntimePlatform platform) => throw new NotImplementedException(); } } diff --git a/test/Sentry.Unity.iOS.Tests/SentryNativeIosTests.cs b/test/Sentry.Unity.iOS.Tests/SentryNativeIosTests.cs index 2fff04518..b71924040 100644 --- a/test/Sentry.Unity.iOS.Tests/SentryNativeIosTests.cs +++ b/test/Sentry.Unity.iOS.Tests/SentryNativeIosTests.cs @@ -9,7 +9,8 @@ public class TestSentryUnityInfo : ISentryUnityInfo public bool IL2CPP { get; set; } public string? Platform { get; } public Il2CppMethods? Il2CppMethods { get; } - public bool IsKnownPlatform() => true; + public bool IsKnownPlatform() => throw new NotImplementedException(); + public bool IsNativeSupportEnabled(SentryUnityOptions options, RuntimePlatform platform) => throw new NotImplementedException(); } public class SentryNativeCocoaTests From 4a5345f5f0daab1f6a993f7d9129f27c9e0319c6 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Fri, 27 Oct 2023 14:14:17 +0200 Subject: [PATCH 06/12] adding fallback path for server --- .../Plugins/macOS/SentryNativeBridge.m | 9 ++++-- .../SentryScriptableObject.cs | 2 +- .../ScriptableSentryUnityOptions.cs | 16 ++++------ src/Sentry.Unity/SentryUnityOptions.cs | 4 +-- .../Sentry.Unity.Android.Tests.csproj | 6 ++++ .../SentryNativeAndroidTests.cs | 13 ++------- .../ScriptableSentryUnityOptionsTests.cs | 16 +++++----- .../SentryUnityOptionsTests.cs | 2 +- .../Sentry.Unity.iOS.Tests.csproj | 6 ++++ .../SentryNativeIosTests.cs | 29 +++++-------------- test/SharedClasses/TestUnityInfo.cs | 22 ++++++++++++++ 11 files changed, 68 insertions(+), 57 deletions(-) create mode 100644 test/SharedClasses/TestUnityInfo.cs diff --git a/package-dev/Plugins/macOS/SentryNativeBridge.m b/package-dev/Plugins/macOS/SentryNativeBridge.m index 0e192a8f4..012a8431d 100644 --- a/package-dev/Plugins/macOS/SentryNativeBridge.m +++ b/package-dev/Plugins/macOS/SentryNativeBridge.m @@ -24,10 +24,15 @@ int SentryNativeBridgeLoadLibrary() if (loadStatus == -1) { loadStatus = 0; // init to "error" do { + // The default path from the executable to the dylib within a .app void *dylib = dlopen("@executable_path/../PlugIns/Sentry.dylib", RTLD_LAZY); if (!dylib) { - NSLog(@"Sentry (bridge): Couldn't load Sentry.dylib - dlopen() failed"); - break; + // Fallback path for the dedicated server setup + dylib = dlopen("@executable_path/PlugIns/Sentry.dylib", RTLD_LAZY); + if (!dylib) { + NSLog(@"Sentry (bridge): Couldn't load Sentry.dylib - dlopen() failed"); + break; + } } LOAD_CLASS_OR_BREAK(SentrySDK) diff --git a/src/Sentry.Unity.Editor/SentryScriptableObject.cs b/src/Sentry.Unity.Editor/SentryScriptableObject.cs index 5c7d19b1f..2e4a06aac 100644 --- a/src/Sentry.Unity.Editor/SentryScriptableObject.cs +++ b/src/Sentry.Unity.Editor/SentryScriptableObject.cs @@ -36,7 +36,7 @@ internal static (SentryUnityOptions?, SentryCliOptions?) ConfiguredBuildTimeOpti SentryUnityOptions? options = null; if (scriptableOptions is not null) { - options = scriptableOptions.ToSentryUnityOptions(isBuilding: true); + options = scriptableOptions.ToSentryUnityOptions(isBuilding: true, unityInfo: null); // Must be non-nullable in the interface otherwise Unity script compilation fails... cliOptions ??= ScriptableObject.CreateInstance(); var setupScript = scriptableOptions.BuildTimeOptionsConfiguration; diff --git a/src/Sentry.Unity/ScriptableSentryUnityOptions.cs b/src/Sentry.Unity/ScriptableSentryUnityOptions.cs index 6ec5ff84e..41e8d5c31 100644 --- a/src/Sentry.Unity/ScriptableSentryUnityOptions.cs +++ b/src/Sentry.Unity/ScriptableSentryUnityOptions.cs @@ -122,11 +122,11 @@ public static string GetConfigPath(string? notDefaultConfigName = null) return null; } - internal SentryUnityOptions ToSentryUnityOptions(bool isBuilding, ISentryUnityInfo? unityInfo = null, IApplication? application = null) + internal SentryUnityOptions ToSentryUnityOptions(bool isBuilding, ISentryUnityInfo? unityInfo, IApplication? application = null) { application ??= ApplicationAdapter.Instance; - var options = new SentryUnityOptions(isBuilding, unityInfo, application) + var options = new SentryUnityOptions(isBuilding, application) { Enabled = Enabled, Dsn = Dsn, @@ -191,15 +191,10 @@ internal SentryUnityOptions ToSentryUnityOptions(bool isBuilding, ISentryUnityIn options.SetupLogging(); - if (!isBuilding) + if (!isBuilding && RuntimeOptionsConfiguration != null) { - if (RuntimeOptionsConfiguration != null) - { - // This has to happen in between options object creation and updating the options based on programmatic changes - RuntimeOptionsConfiguration.Configure(options); - } - - HandlePlatformRestrictions(options, application, unityInfo); + // This has to happen in between options object creation and updating the options based on programmatic changes + RuntimeOptionsConfiguration.Configure(options); } if (!application.IsEditor && options.Il2CppLineNumberSupportEnabled && unityInfo is not null) @@ -207,6 +202,7 @@ internal SentryUnityOptions ToSentryUnityOptions(bool isBuilding, ISentryUnityIn options.AddIl2CppExceptionProcessor(unityInfo); } + HandlePlatformRestrictions(options, application, unityInfo); HandleExceptionFilter(options); if (!AnrDetectionEnabled) diff --git a/src/Sentry.Unity/SentryUnityOptions.cs b/src/Sentry.Unity/SentryUnityOptions.cs index a0739c5e0..058cec11b 100644 --- a/src/Sentry.Unity/SentryUnityOptions.cs +++ b/src/Sentry.Unity/SentryUnityOptions.cs @@ -231,9 +231,9 @@ internal string? DefaultUserId internal List SdkIntegrationNames { get; set; } = new(); - public SentryUnityOptions() : this(false, null, ApplicationAdapter.Instance) { } + public SentryUnityOptions() : this(false, ApplicationAdapter.Instance) { } - internal SentryUnityOptions(bool isBuilding, ISentryUnityInfo? unityInfo, IApplication application) : + internal SentryUnityOptions(bool isBuilding, IApplication application) : this(SentryMonoBehaviour.Instance, application, isBuilding) { } diff --git a/test/Sentry.Unity.Android.Tests/Sentry.Unity.Android.Tests.csproj b/test/Sentry.Unity.Android.Tests/Sentry.Unity.Android.Tests.csproj index 5a2f4edba..45576d0ff 100644 --- a/test/Sentry.Unity.Android.Tests/Sentry.Unity.Android.Tests.csproj +++ b/test/Sentry.Unity.Android.Tests/Sentry.Unity.Android.Tests.csproj @@ -7,4 +7,10 @@ + + + + %(RecursiveDir)%(Filename)%(Extension) + + diff --git a/test/Sentry.Unity.Android.Tests/SentryNativeAndroidTests.cs b/test/Sentry.Unity.Android.Tests/SentryNativeAndroidTests.cs index d6ad6e0db..fb9b63415 100644 --- a/test/Sentry.Unity.Android.Tests/SentryNativeAndroidTests.cs +++ b/test/Sentry.Unity.Android.Tests/SentryNativeAndroidTests.cs @@ -11,7 +11,7 @@ public class SentryNativeAndroidTests private bool _reinstallCalled; private Action? _originalReinstallSentryNativeBackendStrategy; private Action _fakeReinstallSentryNativeBackendStrategy; - private TestSentryUnityInfo _sentryUnityInfo = null!; + private TestUnityInfo _sentryUnityInfo = null!; public SentryNativeAndroidTests() => _fakeReinstallSentryNativeBackendStrategy = () => _reinstallCalled = true; @@ -23,7 +23,7 @@ public void SetUp() Interlocked.Exchange(ref SentryNative.ReinstallSentryNativeBackendStrategy, _fakeReinstallSentryNativeBackendStrategy); _reinstallCalled = false; - _sentryUnityInfo = new TestSentryUnityInfo { IL2CPP = false }; + _sentryUnityInfo = new TestUnityInfo { IL2CPP = false }; } [TearDown] @@ -93,13 +93,4 @@ public void Configure_NativeAndroidSupportDisabled_DoesNotReInitializeNativeBack Assert.False(_reinstallCalled); } } - - public class TestSentryUnityInfo : ISentryUnityInfo - { - public bool IL2CPP { get; set; } - public string? Platform { get; } - public Il2CppMethods? Il2CppMethods { get; } - public bool IsKnownPlatform() => throw new NotImplementedException(); - public bool IsNativeSupportEnabled(SentryUnityOptions options, RuntimePlatform platform) => throw new NotImplementedException(); - } } diff --git a/test/Sentry.Unity.Tests/ScriptableSentryUnityOptionsTests.cs b/test/Sentry.Unity.Tests/ScriptableSentryUnityOptionsTests.cs index c17a9964a..418d724e7 100644 --- a/test/Sentry.Unity.Tests/ScriptableSentryUnityOptionsTests.cs +++ b/test/Sentry.Unity.Tests/ScriptableSentryUnityOptionsTests.cs @@ -18,6 +18,8 @@ class Fixture productName: "TestApplication", version: "0.1.0", persistentDataPath: "test/persistent/data/path"); + + public TestUnityInfo UnityInfo { get; set; } = new(); } class TestOptionsConfiguration : SentryRuntimeOptionsConfiguration @@ -88,7 +90,7 @@ public void ToSentryUnityOptions_ValueMapping_AreEqual(bool isBuilding, bool ena scriptableOptions.DebugOnlyInEditor = false; // Affects Debug otherwise scriptableOptions.DiagnosticLevel = expectedOptions.DiagnosticLevel; - var optionsActual = scriptableOptions.ToSentryUnityOptions(isBuilding, null, _fixture.Application); + var optionsActual = scriptableOptions.ToSentryUnityOptions(isBuilding, _fixture.UnityInfo, _fixture.Application); AssertOptions(expectedOptions, optionsActual); } @@ -116,22 +118,18 @@ public void ToSentryUnityOptions_HasOptionsConfiguration_GetsCalled(bool isBuild var scriptableOptions = ScriptableObject.CreateInstance(); scriptableOptions.RuntimeOptionsConfiguration = optionsConfiguration; - scriptableOptions.ToSentryUnityOptions(isBuilding); + scriptableOptions.ToSentryUnityOptions(isBuilding, _fixture.UnityInfo); Assert.AreEqual(optionsConfiguration.GotCalled, !isBuilding); } [Test] - [TestCase(RuntimePlatform.Switch)] - [TestCase(RuntimePlatform.PS4)] - [TestCase(RuntimePlatform.PS5)] - [TestCase(RuntimePlatform.XboxOne)] - public void ToSentryUnityOptions_UnknownPlatforms_DoesNotAccessDisk(RuntimePlatform targetPlatform) + public void ToSentryUnityOptions_UnknownPlatforms_DoesNotAccessDisk() { var scriptableOptions = ScriptableObject.CreateInstance(); - _fixture.Application.Platform = targetPlatform; + _fixture.UnityInfo = new TestUnityInfo(false); - var options = scriptableOptions.ToSentryUnityOptions(false, null, _fixture.Application); + var options = scriptableOptions.ToSentryUnityOptions(false, _fixture.UnityInfo, _fixture.Application); Assert.IsNull(options.CacheDirectoryPath); Assert.IsFalse(options.AutoSessionTracking); diff --git a/test/Sentry.Unity.Tests/SentryUnityOptionsTests.cs b/test/Sentry.Unity.Tests/SentryUnityOptionsTests.cs index d43be45af..cc372810c 100644 --- a/test/Sentry.Unity.Tests/SentryUnityOptionsTests.cs +++ b/test/Sentry.Unity.Tests/SentryUnityOptionsTests.cs @@ -15,7 +15,7 @@ class Fixture persistentDataPath: "test/persistent/data/path"); public bool IsBuilding { get; set; } - public SentryUnityOptions GetSut() => new SentryUnityOptions(IsBuilding, null, Application); + public SentryUnityOptions GetSut() => new SentryUnityOptions(IsBuilding, Application); } [SetUp] diff --git a/test/Sentry.Unity.iOS.Tests/Sentry.Unity.iOS.Tests.csproj b/test/Sentry.Unity.iOS.Tests/Sentry.Unity.iOS.Tests.csproj index 784ae2340..3851f376b 100644 --- a/test/Sentry.Unity.iOS.Tests/Sentry.Unity.iOS.Tests.csproj +++ b/test/Sentry.Unity.iOS.Tests/Sentry.Unity.iOS.Tests.csproj @@ -7,4 +7,10 @@ + + + + %(RecursiveDir)%(Filename)%(Extension) + + diff --git a/test/Sentry.Unity.iOS.Tests/SentryNativeIosTests.cs b/test/Sentry.Unity.iOS.Tests/SentryNativeIosTests.cs index b71924040..e3967607e 100644 --- a/test/Sentry.Unity.iOS.Tests/SentryNativeIosTests.cs +++ b/test/Sentry.Unity.iOS.Tests/SentryNativeIosTests.cs @@ -4,30 +4,14 @@ namespace Sentry.Unity.iOS.Tests { - public class TestSentryUnityInfo : ISentryUnityInfo - { - public bool IL2CPP { get; set; } - public string? Platform { get; } - public Il2CppMethods? Il2CppMethods { get; } - public bool IsKnownPlatform() => throw new NotImplementedException(); - public bool IsNativeSupportEnabled(SentryUnityOptions options, RuntimePlatform platform) => throw new NotImplementedException(); - } - public class SentryNativeCocoaTests { - private TestSentryUnityInfo _sentryUnityInfo = null!; - - [SetUp] - public void SetUp() - { - _sentryUnityInfo = new TestSentryUnityInfo { IL2CPP = false }; - } - [Test] public void Configure_DefaultConfiguration_iOS() { + var unityInfo = new TestUnityInfo { IL2CPP = false }; var options = new SentryUnityOptions(); - SentryNativeCocoa.Configure(options, _sentryUnityInfo, RuntimePlatform.IPhonePlayer); + SentryNativeCocoa.Configure(options, unityInfo, RuntimePlatform.IPhonePlayer); Assert.IsAssignableFrom(options.ScopeObserver); Assert.IsNotNull(options.CrashedLastRun); Assert.True(options.EnableScopeSync); @@ -36,8 +20,9 @@ public void Configure_DefaultConfiguration_iOS() [Test] public void Configure_NativeSupportDisabled_iOS() { + var unityInfo = new TestUnityInfo(true, false) { IL2CPP = false }; var options = new SentryUnityOptions { IosNativeSupportEnabled = false }; - SentryNativeCocoa.Configure(options, _sentryUnityInfo, RuntimePlatform.IPhonePlayer); + SentryNativeCocoa.Configure(options, unityInfo, RuntimePlatform.IPhonePlayer); Assert.Null(options.ScopeObserver); Assert.Null(options.CrashedLastRun); Assert.False(options.EnableScopeSync); @@ -46,18 +31,20 @@ public void Configure_NativeSupportDisabled_iOS() [Test] public void Configure_DefaultConfiguration_macOS() { + var unityInfo = new TestUnityInfo { IL2CPP = false }; var options = new SentryUnityOptions(); // Note: can't test macOS - throws because it tries to call SentryCocoaBridgeProxy.Init() // but the bridge isn't loaded now... Assert.Throws(() => - SentryNativeCocoa.Configure(options, _sentryUnityInfo, RuntimePlatform.OSXPlayer)); + SentryNativeCocoa.Configure(options, unityInfo, RuntimePlatform.OSXPlayer)); } [Test] public void Configure_NativeSupportDisabled_macOS() { + var unityInfo = new TestUnityInfo(true, false) { IL2CPP = false }; var options = new SentryUnityOptions { MacosNativeSupportEnabled = false }; - SentryNativeCocoa.Configure(options, _sentryUnityInfo, RuntimePlatform.OSXPlayer); + SentryNativeCocoa.Configure(options, unityInfo, RuntimePlatform.OSXPlayer); Assert.Null(options.ScopeObserver); Assert.Null(options.CrashedLastRun); Assert.False(options.EnableScopeSync); diff --git a/test/SharedClasses/TestUnityInfo.cs b/test/SharedClasses/TestUnityInfo.cs new file mode 100644 index 000000000..f67386516 --- /dev/null +++ b/test/SharedClasses/TestUnityInfo.cs @@ -0,0 +1,22 @@ +using Sentry.Unity; +using UnityEngine; + +public class TestUnityInfo : ISentryUnityInfo +{ + private readonly bool _isKnownPlatform; + private readonly bool _isNativeSupportEnabled; + + public bool IL2CPP { get; set; } + public string? Platform { get; } + public Il2CppMethods? Il2CppMethods { get; } + + public TestUnityInfo(bool isKnownPlatform = true, bool isNativeSupportEnabled = true) + { + _isKnownPlatform = isKnownPlatform; + _isNativeSupportEnabled = isNativeSupportEnabled; + } + + public bool IsKnownPlatform() => _isKnownPlatform; + + public bool IsNativeSupportEnabled(SentryUnityOptions options, RuntimePlatform platform) => _isNativeSupportEnabled; +} From 99eee565da843331e074906136cd48639eab3adb Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Fri, 27 Oct 2023 14:14:35 +0200 Subject: [PATCH 07/12] just a bunch of whitespace --- package-dev/Runtime/SentryInitialization.cs | 61 ++++++++++++++++----- 1 file changed, 47 insertions(+), 14 deletions(-) diff --git a/package-dev/Runtime/SentryInitialization.cs b/package-dev/Runtime/SentryInitialization.cs index cf654836a..c495002ae 100644 --- a/package-dev/Runtime/SentryInitialization.cs +++ b/package-dev/Runtime/SentryInitialization.cs @@ -69,7 +69,7 @@ public static void Init() #elif SENTRY_NATIVE_ANDROID SentryNativeAndroid.Configure(options, sentryUnityInfo); #elif SENTRY_NATIVE - SentryNative.Configure(options); + SentryNative.Configure(options, sentryUnityInfo); #elif SENTRY_WEBGL SentryWebGL.Configure(options); #endif @@ -273,22 +273,55 @@ private static void Il2CppNativeStackTraceShim(IntPtr exc, out IntPtr addresses, public bool IsKnownPlatform() { var platform = Application.platform; - return platform == RuntimePlatform.Android || - platform == RuntimePlatform.IPhonePlayer || - platform == RuntimePlatform.WindowsEditor || - platform == RuntimePlatform.WindowsPlayer || - platform == RuntimePlatform.OSXEditor || - platform == RuntimePlatform.OSXPlayer || - platform == RuntimePlatform.LinuxEditor || - platform == RuntimePlatform.LinuxPlayer || - platform == RuntimePlatform.WebGLPlayer + var known = + platform == RuntimePlatform.Android || + platform == RuntimePlatform.IPhonePlayer || + platform == RuntimePlatform.WindowsEditor || + platform == RuntimePlatform.WindowsPlayer || + platform == RuntimePlatform.OSXEditor || + platform == RuntimePlatform.OSXPlayer || + platform == RuntimePlatform.LinuxEditor || + platform == RuntimePlatform.LinuxPlayer || + platform == RuntimePlatform.WebGLPlayer #if UNITY_2021_3_OR_NEWER - || - platform == RuntimePlatform.LinuxServer || - platform == RuntimePlatform.WindowsServer || - platform == RuntimePlatform.OSXServer + || + platform == RuntimePlatform.WindowsServer || + platform == RuntimePlatform.OSXServer || + platform == RuntimePlatform.LinuxServer #endif ; + + Console.WriteLine("Is known platform: " + known); + return known; } + + public bool IsNativeSupportEnabled(SentryUnityOptions options, RuntimePlatform platform) + { + Console.WriteLine("is native support enabled?"); + + switch (platform) + { + case RuntimePlatform.Android: + return options.AndroidNativeSupportEnabled; + case RuntimePlatform.IPhonePlayer: + return options.IosNativeSupportEnabled; + case RuntimePlatform.WindowsPlayer: + return options.WindowsNativeSupportEnabled; + case RuntimePlatform.OSXPlayer: + return options.MacosNativeSupportEnabled; + case RuntimePlatform.LinuxPlayer: + return options.LinuxNativeSupportEnabled; +#if UNITY_2021_3_OR_NEWER + case RuntimePlatform.WindowsServer: + return options.WindowsNativeSupportEnabled; + case RuntimePlatform.OSXServer: + return options.MacosNativeSupportEnabled; + case RuntimePlatform.LinuxServer: + return options.LinuxNativeSupportEnabled; +#endif + default: + return false; + } + } } } From 1de53376c65359ff510e8f28a876bfc8aece6c3c Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Fri, 27 Oct 2023 12:16:29 +0000 Subject: [PATCH 08/12] Format code --- modules/sentry-cocoa | 2 +- src/Sentry.Unity/ScriptableSentryUnityOptions.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/sentry-cocoa b/modules/sentry-cocoa index 7b0d18563..008325304 160000 --- a/modules/sentry-cocoa +++ b/modules/sentry-cocoa @@ -1 +1 @@ -Subproject commit 7b0d185631a6d4b7756468efa464a68725c061d2 +Subproject commit 008325304ada69fa32aa7aeba967b65984f30569 diff --git a/src/Sentry.Unity/ScriptableSentryUnityOptions.cs b/src/Sentry.Unity/ScriptableSentryUnityOptions.cs index 41e8d5c31..5e4235789 100644 --- a/src/Sentry.Unity/ScriptableSentryUnityOptions.cs +++ b/src/Sentry.Unity/ScriptableSentryUnityOptions.cs @@ -191,7 +191,7 @@ internal SentryUnityOptions ToSentryUnityOptions(bool isBuilding, ISentryUnityIn options.SetupLogging(); - if (!isBuilding && RuntimeOptionsConfiguration != null) + if (!isBuilding && RuntimeOptionsConfiguration != null) { // This has to happen in between options object creation and updating the options based on programmatic changes RuntimeOptionsConfiguration.Configure(options); From 22dc59020d9d2d74678f65ef5c74d1a2a51b1f51 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Fri, 27 Oct 2023 16:49:06 +0200 Subject: [PATCH 09/12] linux server native fixes --- src/Sentry.Unity.Native/SentryNative.cs | 2 +- src/Sentry.Unity.Native/SentryNativeBridge.cs | 4 ++-- src/Sentry.Unity/ISentryUnityInfo.cs | 1 + src/Sentry.Unity/ScriptableSentryUnityOptions.cs | 8 +++++++- test/SharedClasses/TestUnityInfo.cs | 5 ++++- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Sentry.Unity.Native/SentryNative.cs b/src/Sentry.Unity.Native/SentryNative.cs index ef1e7af76..28ba38859 100644 --- a/src/Sentry.Unity.Native/SentryNative.cs +++ b/src/Sentry.Unity.Native/SentryNative.cs @@ -26,7 +26,7 @@ public static void Configure(SentryUnityOptions options, ISentryUnityInfo sentry return; } - if (!SentryNativeBridge.Init(options)) + if (!SentryNativeBridge.Init(options, sentryUnityInfo)) { options.DiagnosticLogger? .LogWarning("Sentry native initialization failed - native crashes are not captured."); diff --git a/src/Sentry.Unity.Native/SentryNativeBridge.cs b/src/Sentry.Unity.Native/SentryNativeBridge.cs index c1108b5ba..5c9a38348 100644 --- a/src/Sentry.Unity.Native/SentryNativeBridge.cs +++ b/src/Sentry.Unity.Native/SentryNativeBridge.cs @@ -17,9 +17,9 @@ public static class SentryNativeBridge public static bool CrashedLastRun; - public static bool Init(SentryUnityOptions options) + public static bool Init(SentryUnityOptions options, ISentryUnityInfo sentryUnityInfo) { - _isLinux = ApplicationAdapter.Instance.Platform is RuntimePlatform.LinuxPlayer; + _isLinux = sentryUnityInfo.IsLinux(); var cOptions = sentry_options_new(); diff --git a/src/Sentry.Unity/ISentryUnityInfo.cs b/src/Sentry.Unity/ISentryUnityInfo.cs index b66d88c9e..50eb18874 100644 --- a/src/Sentry.Unity/ISentryUnityInfo.cs +++ b/src/Sentry.Unity/ISentryUnityInfo.cs @@ -8,6 +8,7 @@ public interface ISentryUnityInfo public bool IL2CPP { get; } public Il2CppMethods? Il2CppMethods { get; } public bool IsKnownPlatform(); + public bool IsLinux(); public bool IsNativeSupportEnabled(SentryUnityOptions options, RuntimePlatform platform); } diff --git a/src/Sentry.Unity/ScriptableSentryUnityOptions.cs b/src/Sentry.Unity/ScriptableSentryUnityOptions.cs index 41e8d5c31..e023a0fc9 100644 --- a/src/Sentry.Unity/ScriptableSentryUnityOptions.cs +++ b/src/Sentry.Unity/ScriptableSentryUnityOptions.cs @@ -191,7 +191,13 @@ internal SentryUnityOptions ToSentryUnityOptions(bool isBuilding, ISentryUnityIn options.SetupLogging(); - if (!isBuilding && RuntimeOptionsConfiguration != null) + // Bail early if we're building the player. + if (isBuilding) + { + return options; + } + + if (RuntimeOptionsConfiguration != null) { // This has to happen in between options object creation and updating the options based on programmatic changes RuntimeOptionsConfiguration.Configure(options); diff --git a/test/SharedClasses/TestUnityInfo.cs b/test/SharedClasses/TestUnityInfo.cs index f67386516..c7bcb3e58 100644 --- a/test/SharedClasses/TestUnityInfo.cs +++ b/test/SharedClasses/TestUnityInfo.cs @@ -4,19 +4,22 @@ public class TestUnityInfo : ISentryUnityInfo { private readonly bool _isKnownPlatform; + private readonly bool _isLinux; private readonly bool _isNativeSupportEnabled; public bool IL2CPP { get; set; } public string? Platform { get; } public Il2CppMethods? Il2CppMethods { get; } - public TestUnityInfo(bool isKnownPlatform = true, bool isNativeSupportEnabled = true) + public TestUnityInfo(bool isKnownPlatform = true, bool isLinux = false, bool isNativeSupportEnabled = true) { _isKnownPlatform = isKnownPlatform; + _isLinux = isLinux; _isNativeSupportEnabled = isNativeSupportEnabled; } public bool IsKnownPlatform() => _isKnownPlatform; + public bool IsLinux() => _isLinux; public bool IsNativeSupportEnabled(SentryUnityOptions options, RuntimePlatform platform) => _isNativeSupportEnabled; } From dd2e22eec53a9ffc178571af3359db12294286de Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Fri, 27 Oct 2023 17:27:23 +0200 Subject: [PATCH 10/12] handling platform restrictions --- src/Sentry.Unity/ScriptableSentryUnityOptions.cs | 10 ++++------ test/Sentry.Unity.iOS.Tests/SentryNativeIosTests.cs | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Sentry.Unity/ScriptableSentryUnityOptions.cs b/src/Sentry.Unity/ScriptableSentryUnityOptions.cs index e023a0fc9..da4dfdb3e 100644 --- a/src/Sentry.Unity/ScriptableSentryUnityOptions.cs +++ b/src/Sentry.Unity/ScriptableSentryUnityOptions.cs @@ -153,6 +153,7 @@ internal SentryUnityOptions ToSentryUnityOptions(bool isBuilding, ISentryUnityIn SendDefaultPii = SendDefaultPii, IsEnvironmentUser = IsEnvironmentUser, MaxCacheItems = MaxCacheItems, + CacheDirectoryPath = EnableOfflineCaching ? application.PersistentDataPath : null, InitCacheFlushTimeout = TimeSpan.FromMilliseconds(InitCacheFlushTimeout), SampleRate = SampleRate == 1.0f ? null : SampleRate, // To skip the random check for dropping events ShutdownTimeout = TimeSpan.FromMilliseconds(ShutdownTimeout), @@ -221,11 +222,7 @@ internal SentryUnityOptions ToSentryUnityOptions(bool isBuilding, ISentryUnityIn private void HandlePlatformRestrictions(SentryUnityOptions options, IApplication application, ISentryUnityInfo? unityInfo) { - if (unityInfo?.IsKnownPlatform() == true) - { - options.CacheDirectoryPath = EnableOfflineCaching ? application.PersistentDataPath : null; - } - else + if (unityInfo?.IsKnownPlatform() == false) { // This is only provided on a best-effort basis for other than the explicitly supported platforms. if (options.BackgroundWorker is null) @@ -234,10 +231,11 @@ private void HandlePlatformRestrictions(SentryUnityOptions options, IApplication options.BackgroundWorker = new WebBackgroundWorker(options, SentryMonoBehaviour.Instance); } + // Disable offline caching regardless whether is was enabled or not. + options.CacheDirectoryPath = null; if (EnableOfflineCaching) { options.DiagnosticLogger?.LogDebug("Platform support for offline caching is unknown: disabling."); - options.CacheDirectoryPath = null; } // Requires file access, see https://github.com/getsentry/sentry-unity/issues/290#issuecomment-1163608988 diff --git a/test/Sentry.Unity.iOS.Tests/SentryNativeIosTests.cs b/test/Sentry.Unity.iOS.Tests/SentryNativeIosTests.cs index e3967607e..15026e269 100644 --- a/test/Sentry.Unity.iOS.Tests/SentryNativeIosTests.cs +++ b/test/Sentry.Unity.iOS.Tests/SentryNativeIosTests.cs @@ -20,7 +20,7 @@ public void Configure_DefaultConfiguration_iOS() [Test] public void Configure_NativeSupportDisabled_iOS() { - var unityInfo = new TestUnityInfo(true, false) { IL2CPP = false }; + var unityInfo = new TestUnityInfo(true, false, false) { IL2CPP = false }; var options = new SentryUnityOptions { IosNativeSupportEnabled = false }; SentryNativeCocoa.Configure(options, unityInfo, RuntimePlatform.IPhonePlayer); Assert.Null(options.ScopeObserver); @@ -42,7 +42,7 @@ public void Configure_DefaultConfiguration_macOS() [Test] public void Configure_NativeSupportDisabled_macOS() { - var unityInfo = new TestUnityInfo(true, false) { IL2CPP = false }; + var unityInfo = new TestUnityInfo(true, false, false) { IL2CPP = false }; var options = new SentryUnityOptions { MacosNativeSupportEnabled = false }; SentryNativeCocoa.Configure(options, unityInfo, RuntimePlatform.OSXPlayer); Assert.Null(options.ScopeObserver); From 062dc91b37372d8fd455a97cfc1ee87adc2a628c Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Fri, 27 Oct 2023 17:35:20 +0200 Subject: [PATCH 11/12] IsLinux? --- package-dev/Runtime/SentryInitialization.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/package-dev/Runtime/SentryInitialization.cs b/package-dev/Runtime/SentryInitialization.cs index c495002ae..84fae5034 100644 --- a/package-dev/Runtime/SentryInitialization.cs +++ b/package-dev/Runtime/SentryInitialization.cs @@ -273,7 +273,7 @@ private static void Il2CppNativeStackTraceShim(IntPtr exc, out IntPtr addresses, public bool IsKnownPlatform() { var platform = Application.platform; - var known = + return platform == RuntimePlatform.Android || platform == RuntimePlatform.IPhonePlayer || platform == RuntimePlatform.WindowsEditor || @@ -290,16 +290,22 @@ public bool IsKnownPlatform() platform == RuntimePlatform.LinuxServer #endif ; + } - Console.WriteLine("Is known platform: " + known); - return known; + public bool IsLinux() + { + var platform = Application.platform; + return + platform == RuntimePlatform.LinuxPlayer +#if UNITY_2021_3_OR_NEWER + || platform == RuntimePlatform.LinuxServer +#endif + ; } public bool IsNativeSupportEnabled(SentryUnityOptions options, RuntimePlatform platform) { - Console.WriteLine("is native support enabled?"); - - switch (platform) + switch (platform) { case RuntimePlatform.Android: return options.AndroidNativeSupportEnabled; From 0b744e045ea613dc886dc5ae4c1fb7fa3bfcfd02 Mon Sep 17 00:00:00 2001 From: Stefan Jandl Date: Thu, 2 Nov 2023 09:10:55 +0100 Subject: [PATCH 12/12] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc59c2fe3..faaf85950 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -## Fixes +## Feature - Added the dedicated server platforms to the known platforms to prevent the SDK from interpreting them as restricted platforms (i.e. disabling offline caching, session tracking) ([#1468](https://github.com/getsentry/sentry-unity/pull/1468))