getsentry / sentry-dotnet

Sentry SDK for .NET
https://docs.sentry.io/platforms/dotnet
MIT License
579 stars 206 forks source link

Resolving `InstallationId` writes to disk by default #3607

Open bitsandfoxes opened 5 days ago

bitsandfoxes commented 5 days ago

Problem

Writing to disk on restricted platforms - i.e. Nintento Switch - causes the game to crash: https://github.com/getsentry/sentry-unity/issues/1804

What's happening

We're fetching the installationId lazily https://github.com/getsentry/sentry-dotnet/blob/9ad2caa0c1e21296a90242c06e564d079a59020f/src/Sentry/SentryOptions.cs#L1184

and during event enrichment that installationId gets resolved https://github.com/getsentry/sentry-dotnet/blob/9ad2caa0c1e21296a90242c06e564d079a59020f/src/Sentry/Internal/Enricher.cs#L83

and this causes the InstallationIdHelper to attempt to create a persistent installationId on disk https://github.com/getsentry/sentry-dotnet/blob/9ad2caa0c1e21296a90242c06e564d079a59020f/src/Sentry/Internal/InstallationIdHelper.cs#L30-L33 https://github.com/getsentry/sentry-dotnet/blob/9ad2caa0c1e21296a90242c06e564d079a59020f/src/Sentry/Internal/InstallationIdHelper.cs#L48-L56

Solutions

  1. Change the accessor for InstallationId from internal to public. That way the Unity SDK can overwrite the lazy initialization during options construction. (Hacky) https://github.com/getsentry/sentry-dotnet/blob/9ad2caa0c1e21296a90242c06e564d079a59020f/src/Sentry/SentryOptions.cs#L45
  2. Add controls over writing to disk. That could be a new option. Or we reuse CacheDirectoryPath. With the CacheDirectoryPath set to null we skip all operations writing to disk. We've already got FileSystem in place. https://github.com/getsentry/sentry-dotnet/blob/9ad2caa0c1e21296a90242c06e564d079a59020f/src/Sentry/Internal/FileSystem.cs#L19 We could replace all instances of the SDK directly calling Directory.Create for File.Write going through FileSystem and make that adhere to the options.
bitsandfoxes commented 5 days ago

Going with solution 2. It's been like that for some time so there's no need to hack something together. Let's introduce a new options i.e. DisableFileWrite and route all writing to disk through our FileSystem. Todo: Make sure reading from disk actually works on those restricted platforms.