-
-
Notifications
You must be signed in to change notification settings - Fork 226
Description
Problem
Writing to disk on restricted platforms - i.e. Nintento Switch - causes the game to crash: getsentry/sentry-unity#1804
What's happening
We're fetching the installationId lazily
sentry-dotnet/src/Sentry/SentryOptions.cs
Line 1184 in 9ad2caa
| _lazyInstallationId = new(() => new InstallationIdHelper(this).TryGetInstallationId()); |
and during event enrichment that installationId gets resolved
| eventLike.User.Id ??= _options.InstallationId; |
and this causes the InstallationIdHelper to attempt to create a persistent installationId on disk
sentry-dotnet/src/Sentry/Internal/InstallationIdHelper.cs
Lines 30 to 33 in 9ad2caa
| var id = | |
| TryGetPersistentInstallationId() ?? | |
| TryGetHardwareInstallationId() ?? | |
| GetMachineNameInstallationId(); |
sentry-dotnet/src/Sentry/Internal/InstallationIdHelper.cs
Lines 48 to 56 in 9ad2caa
| private string? TryGetPersistentInstallationId() | |
| { | |
| try | |
| { | |
| var rootPath = options.CacheDirectoryPath ?? | |
| Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); | |
| var directoryPath = Path.Combine(rootPath, "Sentry", options.Dsn!.GetHashString()); | |
| Directory.CreateDirectory(directoryPath); |
Solutions
Change the accessor for(Hacky)InstallationIdfrominternaltopublic. That way the Unity SDK can overwrite the lazy initialization during options construction.
sentry-dotnet/src/Sentry/SentryOptions.cs
Line 45 in 9ad2caa
internal string? InstallationId => _lazyInstallationId.Value; - Add controls over writing to disk. That could be a new option. Or we reuse
CacheDirectoryPath. With theCacheDirectoryPathset tonullwe skip all operations writing to disk. We've already gotFileSystemin place.
public void CreateDirectory(string path) => Directory.CreateDirectory(path);
We could replace all instances of the SDK directly callingDirectory.CreateforFile.Writegoing throughFileSystemand make that adhere to the options.
Metadata
Metadata
Assignees
Labels
Projects
Status