sentry-unity icon indicating copy to clipboard operation
sentry-unity copied to clipboard

Auto Session Tracking should only be enabled by default on Mobile until total process isolation is supported

Open bruno-garcia opened this issue 3 years ago • 5 comments

The session support currently expects exclusive access to the directory it caches data. This works well in sandboxed apps like on mobile but not on Desktop when multiple instances can be executed concurrently.

For this reason, until https://github.com/getsentry/sentry-dotnet/issues/1067 is fixed, we can only opt-in to auto session tracking safely if we are sure there's only 1 instance of the app (mobile, or a player on desktop that only allows one instance running).

When PlayerSettings.forceSingleInstance is set we're safe to enable auto session tracking. Also if the player is Android or iOS and console.

bruno-garcia avatar Jul 19 '21 12:07 bruno-garcia

PlayerSettings.forceSingleInstance is present in UnityEditor.dll and not available in Sentry.Unity (references UnityEngine) where logic for this is executing (SentryOptionsUtility.SetDefaults).

There are 2 possible approaches to determine the platform: Application.platform or Platform dependent compilation.

Suggested way is to use Platform dependent compilation approach. But the problem is still in PlayerSettings.forceSingleInstance not available at the place of calling.

Possible implementation could look something like this

scriptableOptions.AutoSessionTracking = IsAutoSessionTracking(options.AutoSessionTracking);

private bool IsAutoSessionTracking(bool autoSessionTracking)
{
#if UNITY_IOS || UNITY_ANDROID || UNITY_PS4 || UNITY_XBOXONE
    return autoSessionTracking;
#elif UNITY_STANDALONE || UNITY_EDITOR
    return PlayerSettings.forceSingleInstance;
#else
    return autoSessionTracking;
#endif
}

semuserable avatar Jul 30 '21 15:07 semuserable

SentryWindow runs in the editor (Sentry.Unity.Editor), we could read PlayerSettings.forceSingleInstance there and set it to the scriptable object and rely on that value at runtime to disable auto session tracking if the Application.platform is standalone and forceSingleInstance is not true.

Or we live with this until we address getsentry/sentry-dotnet#1067

bruno-garcia avatar Aug 03 '21 21:08 bruno-garcia

The SentryWindow would not get notified about a change to the player settings. But we could read them during pre-build and set it accordingly?

bitsandfoxes avatar Sep 16 '21 12:09 bitsandfoxes

As per a discord discussion:

  • this is rather important for the Windows standalone support so bumping to P1
  • until the dotnet issue is resolved, implement a named mutex so that exactly one instance of the app uses the cache dir

vaind avatar Mar 11 '22 15:03 vaind

Updating impact, priority & status after the workaround has been implemented. The final solution is blocked by the dotnet issue.

vaind avatar Mar 21 '22 10:03 vaind