diff --git a/CHANGELOG.md b/CHANGELOG.md index f26f14ea3..494de7b67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - The SDK now also uses `.sentry-native` as a subdirectory for native support on desktop platforms. It now also falls back to `Application.persistentDataPath` instead of the current working directory. Note: `crashedLastRun` may report `false` for the first time after upgrading. ([#2547](https://github.com/getsentry/sentry-unity/pull/2547)) - The currently experimental Metrics are now opt-in by default ([#2546](https://github.com/getsentry/sentry-unity/pull/2546)) +- When targeting Android, the SDK now syncs `AppStartTime` and `AppBuildType` to the native layer ([#2557](https://github.com/getsentry/sentry-unity/pull/2557)) - When targeting Switch, the SDK will no longer cause the build to fail when native libraries are missing but log a warning instead ([#2541](https://github.com/getsentry/sentry-unity/pull/2541)) - The SDK no longer wrongly disables the org slug field based on assumed the auth-tolken type ([#2537](https://github.com/getsentry/sentry-unity/pull/2537)) diff --git a/modules/app-runner b/modules/app-runner index 0f3a63a67..210bbebe2 160000 --- a/modules/app-runner +++ b/modules/app-runner @@ -1 +1 @@ -Subproject commit 0f3a63a67aeead62b004e1d1548ffe47dc630fb6 +Subproject commit 210bbebe2563bbec1e41b52d9221a3cea20a65c7 diff --git a/src/Sentry.Unity.Android/NativeContextWriter.cs b/src/Sentry.Unity.Android/NativeContextWriter.cs index 7a4162145..9f688adc3 100644 --- a/src/Sentry.Unity.Android/NativeContextWriter.cs +++ b/src/Sentry.Unity.Android/NativeContextWriter.cs @@ -47,10 +47,9 @@ protected override void WriteScope( string? UnityRenderingThreadingMode ) { - // We're only setting the missing contexts, the rest is configured by sentry-java. We could also sync - // the "unity" context, but it doesn't seem so useful and the effort to do is larger because there's no - // class for it in Java - not sure how we could add a generic context object in Java... _sentryJava.WriteScope( + AppStartTime, + AppBuildType, GpuId, GpuName, GpuVendorName, @@ -67,6 +66,8 @@ protected override void WriteScope( GpuMultiThreadedRendering, GpuGraphicsShaderLevel); + CWUtil.WriteApp(AppStartTime, AppBuildType); + CWUtil.WriteGpu( GpuId, GpuName, diff --git a/src/Sentry.Unity.Android/SentryJava.cs b/src/Sentry.Unity.Android/SentryJava.cs index 883bdc2aa..ca74d7668 100644 --- a/src/Sentry.Unity.Android/SentryJava.cs +++ b/src/Sentry.Unity.Android/SentryJava.cs @@ -15,6 +15,8 @@ internal interface ISentryJava public bool? CrashedLastRun(); public void Close(); public void WriteScope( + string? AppStartTime, + string? AppBuildType, int? GpuId, string? GpuName, string? GpuVendorName, @@ -212,6 +214,8 @@ public void Init(SentryUnityOptions options) } public void WriteScope( + string? AppStartTime, + string? AppBuildType, int? GpuId, string? GpuName, string? GpuVendorName, @@ -230,6 +234,15 @@ public void WriteScope( { RunJniSafe(() => { + using var app = new AndroidJavaObject("io.sentry.protocol.App"); + if (AppStartTime is not null) + { + var epochMs = DateTimeOffset.Parse(AppStartTime).ToUnixTimeMilliseconds(); + using var date = new AndroidJavaObject("java.util.Date", epochMs); + app.Set("appStartTime", date); + } + app.SetIfNotNull("buildType", AppBuildType); + using var gpu = new AndroidJavaObject("io.sentry.protocol.Gpu"); gpu.SetIfNotNull("name", GpuName); gpu.SetIfNotNull("id", GpuId); @@ -244,6 +257,7 @@ public void WriteScope( sentry.CallStatic("configureScope", new ScopeCallback(scope => { using var contexts = scope.Call("getContexts"); + contexts.Call("setApp", app); contexts.Call("setGpu", gpu); })); }); diff --git a/test/IntegrationTest/CommonTestCases.ps1 b/test/IntegrationTest/CommonTestCases.ps1 index b38fb675e..c34656851 100644 --- a/test/IntegrationTest/CommonTestCases.ps1 +++ b/test/IntegrationTest/CommonTestCases.ps1 @@ -83,12 +83,6 @@ $CommonTestCases = @( } @{ Name = "Contains app context"; TestBlock = { param($TestSetup, $TestType, $SentryEvent, $RunResult) - - if ($TestType -eq "crash-capture") { - Set-ItResult -Skipped -Because "app context is not synced to sentry-native on Android" - return - } - $SentryEvent.contexts.app | Should -Not -BeNullOrEmpty } } diff --git a/test/Scripts.Integration.Test/Editor/Builder.cs b/test/Scripts.Integration.Test/Editor/Builder.cs index c3f395e67..bb2ae779c 100644 --- a/test/Scripts.Integration.Test/Editor/Builder.cs +++ b/test/Scripts.Integration.Test/Editor/Builder.cs @@ -37,7 +37,7 @@ public static void BuildIl2CPPPlayer(BuildTarget target, BuildTargetGroup group, #endif Debug.Log("Builder: Configuring code stripping level"); -#if UNITY_2022_1_OR_NEWER +#if UNITY_6000_0_OR_NEWER PlayerSettings.SetManagedStrippingLevel(NamedBuildTarget.FromBuildTargetGroup(group), ManagedStrippingLevel.High); #else PlayerSettings.SetManagedStrippingLevel(NamedBuildTarget.FromBuildTargetGroup(group), ManagedStrippingLevel.Low); diff --git a/test/Sentry.Unity.Android.Tests/TestSentryJava.cs b/test/Sentry.Unity.Android.Tests/TestSentryJava.cs index a5c44e1bb..08dbe299c 100644 --- a/test/Sentry.Unity.Android.Tests/TestSentryJava.cs +++ b/test/Sentry.Unity.Android.Tests/TestSentryJava.cs @@ -22,6 +22,8 @@ public void Init(SentryUnityOptions options) { } public void Close() { } public void WriteScope( + string? AppStartTime, + string? AppBuildType, int? GpuId, string? GpuName, string? GpuVendorName,