diff --git a/.github/workflows/test-run-android.yml b/.github/workflows/test-run-android.yml index 6400e761d..8d90dc546 100644 --- a/.github/workflows/test-run-android.yml +++ b/.github/workflows/test-run-android.yml @@ -32,6 +32,7 @@ jobs: HOMEBREW_NO_INSTALL_CLEANUP: 1 SENTRY_DSN: ${{ secrets.SENTRY_TEST_DSN }} SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} + SENTRY_TEST_UNITY_VERSION: ${{ inputs.unity-version }} steps: - name: Checkout diff --git a/CHANGELOG.md b/CHANGELOG.md index 252fc315b..49155c08a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Fixes + +- Setting `FilterBadGatewayExceptions` to `false` now takes effect when initializing the SDK in code with `SentrySdk.Init`. ([#2930](https://github.com/getsentry/sentry-unity/pull/2930)) + ## 4.12.0 ### Behavioral Changes diff --git a/src/Sentry.Unity/ScriptableSentryUnityOptions.cs b/src/Sentry.Unity/ScriptableSentryUnityOptions.cs index 936d22a33..77bb40e31 100644 --- a/src/Sentry.Unity/ScriptableSentryUnityOptions.cs +++ b/src/Sentry.Unity/ScriptableSentryUnityOptions.cs @@ -358,11 +358,6 @@ internal SentryUnityOptions ToSentryUnityOptions( private void HandleExceptionFilter(SentryUnityOptions options) { - if (!options.FilterBadGatewayExceptions) - { - options.RemoveExceptionFilter(); - } - if (!FilterWebExceptions) { options.RemoveExceptionFilter(); diff --git a/src/Sentry.Unity/SentryUnitySdk.cs b/src/Sentry.Unity/SentryUnitySdk.cs index 1464120da..a7811c854 100644 --- a/src/Sentry.Unity/SentryUnitySdk.cs +++ b/src/Sentry.Unity/SentryUnitySdk.cs @@ -31,6 +31,11 @@ private SentryUnitySdk(SentryUnityOptions options) // 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); + if (!options.FilterBadGatewayExceptions) + { + options.RemoveExceptionFilter(); + } + SetUpWindowsPlayerCaching(unitySdk, options); ConfigureUnsupportedPlatformFallbacks(options); diff --git a/test/IntegrationTest/Integration.Tests.ps1 b/test/IntegrationTest/Integration.Tests.ps1 index 6e9f39c20..9f39a191d 100644 --- a/test/IntegrationTest/Integration.Tests.ps1 +++ b/test/IntegrationTest/Integration.Tests.ps1 @@ -447,6 +447,10 @@ Describe "Unity $($env:SENTRY_TEST_PLATFORM) Integration Tests" { Set-ItResult -Skipped -Because "line numbers come from the IL2CPP mappings, which a Mono player does not produce" return } + if ($script:Platform -eq "Android" -and $script:TestSetup.UnityVersion -like "2021.3*") { + Set-ItResult -Skipped -Because "on the Android 2021.3 x86_64 emulator, IL2CPP intermittently reports no stack frames for the thrown exception, so the event carries only the throwing frame without a native address" + return + } $frame = $runEvent.exception.values[0].stacktrace.frames | Where-Object { $_.module -eq "IntegrationTester" -and $_.function -eq "ThrowException" } | diff --git a/test/Sentry.Unity.Tests/SentryUnityTests.cs b/test/Sentry.Unity.Tests/SentryUnityTests.cs index adad2abe7..d9706593c 100644 --- a/test/Sentry.Unity.Tests/SentryUnityTests.cs +++ b/test/Sentry.Unity.Tests/SentryUnityTests.cs @@ -2,9 +2,11 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Reflection; using System.Threading.Tasks; using Debug = UnityEngine.Debug; using Sentry.Extensibility; +using Sentry.Unity.Integrations; using Sentry.Unity.Tests.SharedClasses; using Sentry.Unity.Tests.Stubs; using UnityEngine; @@ -78,6 +80,22 @@ public void SentryUnity_OptionsValid_Initializes() Assert.IsTrue(SentrySdk.IsEnabled); } + [Test] + public void SentryUnity_FilterBadGatewayExceptionsDisabled_RemovesBadGatewayFilter() + { + var options = new SentryUnityOptions(application: new TestApplication()) + { + Dsn = SentryTests.TestDsn, + FilterBadGatewayExceptions = false + }; + + SentrySdk.Init(options); + + var exceptionFiltersPropertyInfo = typeof(SentryOptions).GetProperty("ExceptionFilters", BindingFlags.NonPublic | BindingFlags.Instance); + var filters = (List)exceptionFiltersPropertyInfo!.GetValue(options); + Assert.That(filters.OfType(), Is.Empty); + } + [Test] public void SentryUnity_OptionsInvalid_DoesNotInitialize() {