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

Feat: Automatic user IDs on native crashes & .NET events #728

Merged
merged 13 commits into from
May 16, 2022
Merged

Conversation

vaind
Copy link
Collaborator

@vaind vaind commented May 4, 2022

closes #606

  • android -> dotnet
  • iOS-> dotnet
  • macOS -> dotnet
  • Unity -> dotnet -> Windows
  • Unity -> dotnet -> Linux
  • Unity -> dotnet on WebGL. Notes:
    • the ID seems to persist across tabs & browser sessions, likely a cookie or local storage based, so pretty useful and in line with other platforms
    • opening in a different browser or a private tab gives a new ID, which is also OK

@vaind vaind force-pushed the feat/user-id-sync branch 2 times, most recently from e98a20f to 0be2cce Compare May 11, 2022 08:41
@vaind vaind changed the title Feat: synchronize user IDs between native & dotnet Feat: Automatic user IDs on native crashes & .NET events May 11, 2022
@vaind vaind marked this pull request as ready for review May 11, 2022 12:17
@vaind vaind force-pushed the feat/user-id-sync branch 3 times, most recently from c9ad8ca to b6424d4 Compare May 12, 2022 08:41
Copy link
Contributor

@bitsandfoxes bitsandfoxes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in summary:

  • For Android, Cocoa (iOS and macOS) we fetch the ID from the native SDKs (which is great because they initialize first)
  • For Native (Windows & Linux) we set the ID from the C# layer.

This is great!

CHANGELOG.md Show resolved Hide resolved
@@ -27,4 +27,9 @@
Overwrite="true"/>
</Target>

<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL that this exists. @bruno-garcia would that help with some of the issues we had with some of the .NET SDK internals we did not want to make public like inside of SentryOptions for SentryUnityOptions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is the same as adding [assembly: InternalsVisibleToAttribute(..) in C#. Just another way.

Comment on lines +123 to +131
_defaultUserId = value;
if (_defaultUserId is null)
{
DiagnosticLogger?.LogWarning("Couldn't set the default user ID - the value is NULL.");
}
else
{
DiagnosticLogger?.LogDebug("Setting '{0}' as the default user ID.", _defaultUserId);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_defaultUserId = value;
if (_defaultUserId is null)
{
DiagnosticLogger?.LogWarning("Couldn't set the default user ID - the value is NULL.");
}
else
{
DiagnosticLogger?.LogDebug("Setting '{0}' as the default user ID.", _defaultUserId);
}
if (value is null)
{
DiagnosticLogger?.LogWarning("Couldn't set the default user ID - the value is NULL.");
}
else
{
_defaultUserId = value;
DiagnosticLogger?.LogDebug("Setting '{0}' as the default user ID.", _defaultUserId);
}

Should this not set the id if it logs that it can't?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the goal to reset to null as it'll be needed later to "unset"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this not set the id if it logs that it can't?

this is a setter - doesn't feel right to ignore the value being passed (i.e. not set)

@@ -27,4 +27,9 @@
Overwrite="true"/>
</Target>

<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is the same as adding [assembly: InternalsVisibleToAttribute(..) in C#. Just another way.

Comment on lines +123 to +131
_defaultUserId = value;
if (_defaultUserId is null)
{
DiagnosticLogger?.LogWarning("Couldn't set the default user ID - the value is NULL.");
}
else
{
DiagnosticLogger?.LogDebug("Setting '{0}' as the default user ID.", _defaultUserId);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the goal to reset to null as it'll be needed later to "unset"?

@@ -36,6 +37,9 @@ public static void Configure(SentryUnityOptions options)
options.DiagnosticLogger?.LogWarning("Attaching screenshots on WebGL is disabled - " +
"it currently produces blank screenshots mid-frame.");
}

// Use AnalyticsSessionInfo.userId as the default UserID in native & dotnet
options.DefaultUserId = AnalyticsSessionInfo.userId;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is an ID that can be used to link the user across apps/services, we shouldn't be using it here.
We purposely on some GUIDs we create so that we can have some consistency in detecting "number ofusers impacted" but the goal is never to do actual user tracking. For that reason we've dropped "Android ID" also, for example

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JS will default to the connection IP Address, and there's no native so we might be better off without anything here

Copy link
Collaborator Author

@vaind vaind May 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. we don't have sentry-js (yet)

  2. therefore setting this here only affects c# events

  3. I'm setting it here because that's what feeled right - each native platform integration defines the source for the DefaultUserId value

  4. If this is an ID that can be used to link the user across apps/services, we shouldn't be using it here.

    I really don't think so. It's an installation ID.

    https://docs.unity3d.com/ScriptReference/Analytics.AnalyticsSessionInfo-userId.html
    A random GUID uniquely identifying sessions played on the same instance of your game or app.
    Unity generates the userId GUID immediately after installation. The userId value is only regenerated if the user re-installs the game.

@vaind
Copy link
Collaborator Author

vaind commented May 16, 2022

since this is already approved I'm merging to avoid conflicts in #747 - if we need to make changes based on those unresolved conversations, let's do them in the other PR.

@vaind vaind merged commit 1db2fa4 into main May 16, 2022
@vaind vaind deleted the feat/user-id-sync branch May 16, 2022 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Align the default user-id between the C# and native layers
3 participants