Skip to content

Commit

Permalink
fix: Disable file-write on unknown platforms (#1814)
Browse files Browse the repository at this point in the history
  • Loading branch information
bitsandfoxes authored Oct 7, 2024
1 parent e4d3d4d commit 68a92a1
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 47 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@

## Unreleased

### API Changes

- The `SentrySdk.Metrics` module is deprecated and will be removed in the next major release.
Sentry will reject all metrics sent after October 7, 2024.
Learn more: https://sentry.zendesk.com/hc/en-us/articles/26369339769883-Upcoming-API-Changes-to-Metrics ([#3619](https://github.com/getsentry/sentry-dotnet/pull/3619))

### Fixes

- The SDK now uses the .NET SDK's `Options.FileWriteDisabled` to opt-out on any writing operations on 'unknown' platforms such as the Nintendo Switch ([1814](https://github.com/getsentry/sentry-unity/pull/1814))
- The SDK no longer freezes the game during shutdown when targeting WebGL ([#3619](https://github.com/getsentry/sentry-dotnet/pull/3619))
- The SDK no longer passes a mangled `gpu.vendorId` to the Android native layer ([#1813](https://github.com/getsentry/sentry-unity/pull/1813))

### Features
Expand All @@ -16,6 +24,9 @@
- Bump Native SDK from v0.7.9 to v0.7.10 ([#1809](https://github.com/getsentry/sentry-unity/pull/1809))
- [changelog](https://github.com/getsentry/sentry-native/blob/master/CHANGELOG.md#0710)
- [diff](https://github.com/getsentry/sentry-native/compare/0.7.9...0.7.10)
- Bump .NET SDK from v4.10.2 to v4.12.0 ([#1823](https://github.com/getsentry/sentry-unity/pull/1823))
- [changelog](https://github.com/getsentry/sentry-dotnet/blob/main/CHANGELOG.md#4120)
- [diff](https://github.com/getsentry/sentry-dotnet/compare/4.10.2...4.12.0)
- Bump CLI from v2.34.1 to v2.36.6 ([#1788](https://github.com/getsentry/sentry-unity/pull/1788), [#1792](https://github.com/getsentry/sentry-unity/pull/1792), [#1796](https://github.com/getsentry/sentry-unity/pull/1796), [#1810](https://github.com/getsentry/sentry-unity/pull/1810), [#1815](https://github.com/getsentry/sentry-unity/pull/1815), [#1819](https://github.com/getsentry/sentry-unity/pull/1819), [#1820](https://github.com/getsentry/sentry-unity/pull/1820), [#1822](https://github.com/getsentry/sentry-unity/pull/1822))
- [changelog](https://github.com/getsentry/sentry-cli/blob/master/CHANGELOG.md#2366)
- [diff](https://github.com/getsentry/sentry-cli/compare/2.34.1...2.36.6)
Expand Down
9 changes: 2 additions & 7 deletions src/Sentry.Unity/ScriptableSentryUnityOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ private void HandlePlatformRestrictions(SentryUnityOptions options, IApplication
{
if (unityInfo?.IsKnownPlatform() == false)
{
options.DisableFileWrite = true;

// This is only provided on a best-effort basis for other than the explicitly supported platforms.
if (options.BackgroundWorker is null)
{
Expand All @@ -259,13 +261,6 @@ private void HandlePlatformRestrictions(SentryUnityOptions options, IApplication
options.DiagnosticLogger?.LogDebug("Platform support for automatic session tracking is unknown: disabling.");
options.AutoSessionTracking = false;
}

// Requires file access
if (options.TracesSampleRate > 0.0f)
{
options.DiagnosticLogger?.LogDebug("Platform support for tracing is unknown: disabling.");
options.TracesSampleRate = null;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/sentry-dotnet
Submodule sentry-dotnet updated 74 files
+2 −0 .github/actions/environment/action.yml
+37 −2 .github/workflows/build.yml
+2 −2 .github/workflows/codeql-analysis.yml
+1 −1 .github/workflows/device-tests-android.yml
+57 −0 CHANGELOG.md
+2 −2 Directory.Build.props
+1 −1 modules/Ben.Demystifier
+1 −1 modules/perfview
+1 −1 modules/sentry-cocoa
+1 −1 modules/sentry-native
+9 −0 samples/Sentry.Samples.AspNetCore.Mvc/Controllers/HomeController.cs
+28 −3 samples/Sentry.Samples.AspNetCore.Mvc/Program.cs
+2 −0 samples/Sentry.Samples.Console.Metrics/Program.cs
+140 −0 src/Sentry.Bindings.Cocoa/ApiDefinitions.cs
+0 −7 src/Sentry.Bindings.Cocoa/PrivateApiDefinitions.cs
+7 −2 src/Sentry.Extensions.Logging/SentryLogger.cs
+5 −1 src/Sentry.Hangfire/SentryServerFilter.cs
+6 −0 src/Sentry.NLog/SentryTarget.cs
+6 −1 src/Sentry.Serilog/SentrySink.cs
+2 −0 src/Sentry/BindableSentryOptions.cs
+73 −32 src/Sentry/Extensibility/DiagnosticLoggerExtensions.cs
+3 −5 src/Sentry/Extensibility/DisabledHub.cs
+3 −0 src/Sentry/Extensibility/HubAdapter.cs
+2 −0 src/Sentry/FileAttachmentContent.cs
+42 −6 src/Sentry/GlobalSessionManager.cs
+33 −4 src/Sentry/Http/HttpTransportBase.cs
+1 −12 src/Sentry/ISentryJsonSerializable.cs
+0 −1 src/Sentry/Integrations/WinUIUnhandledExceptionIntegration.cs
+2 −1 src/Sentry/Internal/DebugStackTrace.cs
+0 −53 src/Sentry/Internal/FileSystem.cs
+29 −0 src/Sentry/Internal/FileSystemBase.cs
+10 −1 src/Sentry/Internal/Http/CachingTransport.cs
+53 −8 src/Sentry/Internal/Hub.cs
+13 −6 src/Sentry/Internal/IFileSystem.cs
+19 −4 src/Sentry/Internal/InstallationIdHelper.cs
+2 −2 src/Sentry/Internal/Json.cs
+25 −0 src/Sentry/Internal/ReadOnlyFilesystem.cs
+63 −0 src/Sentry/Internal/ReadWriteFileSystem.cs
+17 −1 src/Sentry/Internal/SdkComposer.cs
+3 −0 src/Sentry/Internal/SystemDiagnosticsMetricsListener.cs
+12 −10 src/Sentry/Protocol/Device.cs
+7 −7 src/Sentry/Sentry.csproj
+15 −6 src/Sentry/SentryOptions.cs
+5 −2 src/Sentry/SentrySdk.cs
+1 −0 src/Sentry/buildTransitive/Sentry.targets
+24 −10 test/Sentry.AspNet.Tests/HttpContextExtensionsTests.cs
+7 −0 test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsEfAsync.DotNet6_0.verified.txt
+7 −0 test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsEfAsync.DotNet7_0.verified.txt
+7 −0 test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsEfAsync.DotNet8_0.verified.txt
+7 −0 test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsEfAsync.Net4_8.verified.txt
+7 −0 test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsSqlAsync.verified.txt
+7 −0 test/Sentry.EntityFramework.Tests/IntegrationTests.Simple.verified.txt
+16 −123 test/Sentry.Extensions.Logging.Tests/SentryLoggerTests.cs
+52 −0 test/Sentry.Hangfire.Tests/ServerFilterTests.cs
+1 −3 test/Sentry.Maui.Tests/SentryMauiAppBuilderExtensionsTests.cs
+25 −0 test/Sentry.NLog.Tests/SentryTargetTests.cs
+6 −3 test/Sentry.Profiling.Tests/SamplingTransactionProfilerTests.cs
+19 −9 test/Sentry.Serilog.Tests/SentrySinkTests.cs
+53 −27 test/Sentry.Testing/FakeFileSystem.cs
+4 −10 test/Sentry.Testing/TempDirectory.cs
+9 −0 test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt
+9 −0 test/Sentry.Tests/ApiApprovalTests.Run.DotNet7_0.verified.txt
+9 −0 test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt
+9 −0 test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt
+59 −13 test/Sentry.Tests/GlobalSessionManagerTests.cs
+64 −7 test/Sentry.Tests/HubTests.cs
+4 −3 test/Sentry.Tests/Internals/BackgroundWorkerTests.cs
+39 −54 test/Sentry.Tests/Internals/Http/CachingTransportTests.cs
+6 −4 test/Sentry.Tests/Internals/InstallationIdHelperTests.cs
+140 −0 test/Sentry.Tests/Protocol/DeviceTests.cs
+33 −0 test/Sentry.Tests/ReadOnlyFileSystemTests.cs
+104 −0 test/Sentry.Tests/ReadWriteFileSystemTests.cs
+2 −4 test/Sentry.Tests/SentryClientTests.cs
+1 −4 test/Sentry.Tests/SentrySdkTests.cs
43 changes: 43 additions & 0 deletions test/Sentry.Unity.Tests/ScriptableSentryUnityOptionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using NUnit.Framework;
using Sentry.Extensibility;
using Sentry.Unity.Integrations;
using Sentry.Unity.Tests.Stubs;
using UnityEngine;

Expand Down Expand Up @@ -135,6 +139,45 @@ public void ToSentryUnityOptions_UnknownPlatforms_DoesNotAccessDisk()
Assert.IsFalse(options.AutoSessionTracking);
}

[Test]
public void ToSentryUnityOptions_WebExceptionFilterAdded()
{
var scriptableOptions = ScriptableObject.CreateInstance<ScriptableSentryUnityOptions>();
_fixture.UnityInfo = new TestUnityInfo(true);

var options = scriptableOptions.ToSentryUnityOptions(false, _fixture.UnityInfo, _fixture.Application);

var exceptionFiltersPropertyInfo = typeof(SentryOptions).GetProperty("ExceptionFilters", BindingFlags.NonPublic | BindingFlags.Instance);
var filters = exceptionFiltersPropertyInfo.GetValue(options) as List<IExceptionFilter>;
Assert.True(filters.OfType<UnityWebExceptionFilter>().Any());
}

[Test]
public void ToSentryUnityOptions_UnitySocketExceptionFilterAdded()
{
var scriptableOptions = ScriptableObject.CreateInstance<ScriptableSentryUnityOptions>();
_fixture.UnityInfo = new TestUnityInfo(true);

var options = scriptableOptions.ToSentryUnityOptions(false, _fixture.UnityInfo, _fixture.Application);

var exceptionFiltersPropertyInfo = typeof(SentryOptions).GetProperty("ExceptionFilters", BindingFlags.NonPublic | BindingFlags.Instance);
var filters = exceptionFiltersPropertyInfo.GetValue(options) as List<IExceptionFilter>;
Assert.True(filters.OfType<UnitySocketExceptionFilter>().Any());
}

[Test]
public void ToSentryUnityOptions_UnityBadGatewayExceptionFilterAdded()
{
var scriptableOptions = ScriptableObject.CreateInstance<ScriptableSentryUnityOptions>();
_fixture.UnityInfo = new TestUnityInfo(true);

var options = scriptableOptions.ToSentryUnityOptions(false, _fixture.UnityInfo, _fixture.Application);

var exceptionFiltersPropertyInfo = typeof(SentryOptions).GetProperty("ExceptionFilters", BindingFlags.NonPublic | BindingFlags.Instance);
var filters = exceptionFiltersPropertyInfo.GetValue(options) as List<IExceptionFilter>;
Assert.True(filters.OfType<UnityBadGatewayExceptionFilter>().Any());
}

public static void AssertOptions(SentryUnityOptions expected, SentryUnityOptions actual)
{
Assert.AreEqual(expected.Enabled, actual.Enabled);
Expand Down
13 changes: 0 additions & 13 deletions test/Sentry.Unity.Tests/UnityBadGatewayExceptionFilterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,6 @@ public void Filter_FiltersBadGatewayExceptionsOfTypeException() =>

Assert.IsTrue(new UnityBadGatewayExceptionFilter().Filter(new Exception(UnityBadGatewayExceptionFilter.Message)));

[Test]
public void Init_WithDefaultOptions_DoesNotSendBadGatewayExceptions()
{
LogAssert.ignoreFailingMessages = true; // The TestHttpClientHandler will complain about timing out (and it should!)

using var _ = SentryTests.InitSentrySdk(testHttpClientHandler: _testHttpClientHandler);

SentrySdk.CaptureException(new Exception(UnityBadGatewayExceptionFilter.Message + _identifyingEventValue));

var createdEvent = _testHttpClientHandler.GetEvent(_identifyingEventValue, _eventReceiveTimeout);
Assert.AreEqual(string.Empty, createdEvent);
}

internal IDisposable InitSentrySdk(Action<SentryUnityOptions>? configure = null)
{
SentryUnity.Init(options =>
Expand Down
13 changes: 0 additions & 13 deletions test/Sentry.Unity.Tests/UnitySocketExceptionFilterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,4 @@ public void SetUp() =>
[Test]
public void Filter_FiltersBadGatewayExceptionsOfTypeException() =>
Assert.IsTrue(new UnitySocketExceptionFilter().Filter(new System.Net.Sockets.SocketException(10049)));

[Test]
public void Init_WithDefaultOptions_DoesNotSendFilteredSocketExceptions()
{
LogAssert.ignoreFailingMessages = true; // The TestHttpClientHandler will complain about timing out (and it should!)

using var _ = SentryTests.InitSentrySdk(testHttpClientHandler: _testHttpClientHandler);

SentrySdk.CaptureException(new System.Net.Sockets.SocketException(10049)); // The requested address is not valid in this context

var createdEvent = _testHttpClientHandler.GetEvent(UnitySocketExceptionFilter.Message, _eventReceiveTimeout);
Assert.AreEqual(string.Empty, createdEvent);
}
}
14 changes: 1 addition & 13 deletions test/Sentry.Unity.Tests/UnityWebExceptionFilterTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using NUnit.Framework;
using Sentry.Unity.Integrations;
using UnityEngine;
using UnityEngine.TestTools;

namespace Sentry.Unity.Tests;
Expand All @@ -17,17 +18,4 @@ public void SetUp() =>
[Test]
public void Filter_FiltersBadGatewayExceptionsOfTypeException() =>
Assert.IsTrue(new UnityWebExceptionFilter().Filter(new System.Net.WebException(UnityWebExceptionFilter.Message)));

[Test]
public void Init_WithDefaultOptions_DoesNotSendFilteredWebExceptions()
{
LogAssert.ignoreFailingMessages = true; // The TestHttpClientHandler will complain about timing out (and it should!)

using var _ = SentryTests.InitSentrySdk(testHttpClientHandler: _testHttpClientHandler);

SentrySdk.CaptureException(new System.Net.WebException(UnityWebExceptionFilter.Message));

var createdEvent = _testHttpClientHandler.GetEvent(UnityWebExceptionFilter.Message, _eventReceiveTimeout);
Assert.AreEqual(string.Empty, createdEvent);
}
}

0 comments on commit 68a92a1

Please # to comment.