diff --git a/package-dev/Runtime/SentryInitialization.cs b/package-dev/Runtime/SentryInitialization.cs index 3d5071b1a..b8a428fb7 100644 --- a/package-dev/Runtime/SentryInitialization.cs +++ b/package-dev/Runtime/SentryInitialization.cs @@ -57,8 +57,8 @@ internal static class SentryInitialization #endif private static void Init() { - // We're setting up `UnityInfo` and the platform specific configure callbacks as the very first thing. - // These are required to be available during initialization. + // We're setting up platform specific configuration as the very first thing. + // These are required to be available during initialization, i.e. UnityInfo and MainThreadData. SetUpPlatformServices(); // Loading the options invokes the ScriptableOption`Configure` callback. Users can disable the SDK via code. @@ -81,6 +81,7 @@ private static void Init() private static void SetUpPlatformServices() { + SentryPlatformServices.CollectMainThreadData(); SentryPlatformServices.UnityInfo = new SentryUnityInfo(); #if SENTRY_NATIVE_COCOA diff --git a/src/Sentry.Unity.Android/SentryNativeAndroid.cs b/src/Sentry.Unity.Android/SentryNativeAndroid.cs index 6c3e6daea..76a0608ea 100644 --- a/src/Sentry.Unity.Android/SentryNativeAndroid.cs +++ b/src/Sentry.Unity.Android/SentryNativeAndroid.cs @@ -22,8 +22,6 @@ public static class SentryNativeAndroid /// The Sentry Unity options to use. public static void Configure(SentryUnityOptions options) { - MainThreadData.CollectData(); - options.DiagnosticLogger?.LogInfo("Attempting to configure native support via the Android SDK"); if (!options.AndroidNativeSupportEnabled) diff --git a/src/Sentry.Unity/NativeUtils/SentryPlatformServices.cs b/src/Sentry.Unity/NativeUtils/SentryPlatformServices.cs index ceda6adb1..5f8e9a53b 100644 --- a/src/Sentry.Unity/NativeUtils/SentryPlatformServices.cs +++ b/src/Sentry.Unity/NativeUtils/SentryPlatformServices.cs @@ -4,8 +4,9 @@ namespace Sentry.Unity.NativeUtils; /// /// These are SDK's services that are only available at runtime and cannot be baked into the SDK. The -/// SentryInitialization.cs is provided as .cs and gets compiled with the game. It sets IUnityInfo -/// and the PlatformConfiguration callback during the game's startup so that they are available during initializtion. +/// SentryInitialization.cs is provided as .cs and gets compiled with the game. +/// It sets IUnityInfo and the PlatformConfiguration callback during the game's startup, as well as collecting +/// the MainThreadData. These are then available during both auto and manual initialization. /// /// Consider this internal. public static class SentryPlatformServices @@ -31,4 +32,10 @@ public static ISentryUnityInfo UnityInfo /// The PlatformConfiguration callback is responsible for configuring the native SDK and setting up scope sync. /// public static Action? PlatformConfiguration { get; set; } + + /// + /// Collects comprehensive system and device information that must be accessed on Unity's main thread. + /// This includes hardware specs (CPU, GPU, memory), device details, graphics capabilities, + /// + public static void CollectMainThreadData() => MainThreadData.CollectData(); } diff --git a/src/Sentry.Unity/SentryUnitySdk.cs b/src/Sentry.Unity/SentryUnitySdk.cs index 99252ee3f..4b4654f17 100644 --- a/src/Sentry.Unity/SentryUnitySdk.cs +++ b/src/Sentry.Unity/SentryUnitySdk.cs @@ -28,8 +28,6 @@ private SentryUnitySdk(SentryUnityOptions options) return null; } - MainThreadData.CollectData(); - // Some integrations are controlled through a flag and opt-in. Adding these integrations late so we have equal // behaviour whether the options got created through the ScriptableObject or the SDK gets manually initialized AddIntegrations(options); diff --git a/test/Sentry.Unity.Tests/ContextWriterTests.cs b/test/Sentry.Unity.Tests/ContextWriterTests.cs index eca1dd663..2e08a3895 100644 --- a/test/Sentry.Unity.Tests/ContextWriterTests.cs +++ b/test/Sentry.Unity.Tests/ContextWriterTests.cs @@ -63,7 +63,6 @@ public void Arguments() CopyTextureSupport = new(() => "CopyTextureSupport"), RenderingThreadingMode = new(() => "RenderingThreadingMode"), StartTime = new(() => DateTimeOffset.UtcNow), - }; var context = new MockContextWriter(); var options = new SentryUnityOptions(application: _testApplication, behaviour: _sentryMonoBehaviour) @@ -79,6 +78,8 @@ public void Arguments() // act MainThreadData.SentrySystemInfo = sysInfo; + MainThreadData.CollectData(); // In an actual game, this happens outside and before Init() + SentrySdk.Init(options); Assert.IsTrue(context.SyncFinished.WaitOne(TimeSpan.FromSeconds(10)));