Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolving InstallationId writes to disk by default #3607

Closed
bitsandfoxes opened this issue Sep 13, 2024 · 1 comment · Fixed by #3614
Closed

Resolving InstallationId writes to disk by default #3607

bitsandfoxes opened this issue Sep 13, 2024 · 1 comment · Fixed by #3614
Labels
Bug Something isn't working Offline Caching

Comments

@bitsandfoxes
Copy link
Contributor

bitsandfoxes commented Sep 13, 2024

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

_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

var id =
TryGetPersistentInstallationId() ??
TryGetHardwareInstallationId() ??
GetMachineNameInstallationId();

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

  1. Change the accessor for InstallationId from internal to public. That way the Unity SDK can overwrite the lazy initialization during options construction. (Hacky)
    internal string? InstallationId => _lazyInstallationId.Value;
  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.
    public void CreateDirectory(string path) => Directory.CreateDirectory(path);

    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 bitsandfoxes added Bug Something isn't working Offline Caching labels Sep 13, 2024
@bitsandfoxes
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Offline Caching
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant