You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
(MAUI) user.id is always set and can't remove it with SendDefaultPii or null #4172
From what I can tell, we do want to have some default value for the User.Id. This seems to be the case on iOS and Android, although I don't see any similar docs for PHP, Java or Python... so maybe it serves some special purpose on Mobile platforms.
@bruno-garcia if SendDefaultPii is false, should we leave the Id blank (same as we do for IpAddress and Username)?
Out of curiosity, why not set User.Id ??= _options.InstallationId at the global scope when initializing the app? This way users will have this info when not set and will also be able to remove it if not required
So I checked with Bruno. We intentionally set User.Id to a non-null value so that Session health metrics work on Mobile platforms. The installationId is just a GUID that we generate, so nothing super sensitive (it just let's us distinguish sessions from different users).
We could, as you suggest, do this when initialising the global/root scope for the app though (rather than in an enricher) so that you could overwrite this if you didn't care about session health metrics and you were worried about sending this.
On the app that I was looking, they are using manual session metrics, because they only want to monitor users after they login and when they logout, to stop the session manually, since it's an app for business, more than one person could be using the same app on the same session.
having the user.id set on the global scope would make it easier to clear it once and make it easier to actually know how many users are using the app, without counting the install ID
Note that we can use InstallationId on Sessions while not setting it on the user scope. Sessions is detatched from errors data.
Having the id set by default but allowing the users to reset to null on BeforeSend makes sense though
In fact, BeforeSend should be the last thing that touches the event before we send it, to allow the user to have a full picture of what's being sent. And allow the user to make the mutations they want
SetBeforeSend is indeed a good option, but it also leaves native SDKs to set their Installaiton id that doesn't go towards C# BeforeSend
sentry.native.android.dotnet
sentry.java.android.dotnet
for .NET BeforeSend I just added a check to see if user.id has - and set it to null, but that logic wouldn't work for the native SDKs, if they even go towards .NET BeforeSend
hopefully I won't need this filter on discover to count users lol
@lucas-zimerman I took a look at this. Initially I was thinking to move the functionality from the enricher into the global scope.
Currently the enricher gets applied in two places:
SentryClient.CaptureTransaction: Here it's called immediately after scope.Apply so if we stored the user id in the root scope, that would work fine.
MainSentryEventProcessor.Process: This is the one that causes problems since it gets applied after the user does things like setting the user.id to null in a ConfigureScope callback. The event processor itself gets called from SentryClient.DoSendEvent, however, and once again this happens after a call to scope.Apply.
First idea
Since both locations where the enricher is applied are in code that runs after scope.Apply, rather than using the main event processor to set the user id, we could instead set this in the root scope. That way it the SDK user does not override this, it will be applied as normal. If they do override it, then their value will take precedence (for example, they could set it to null via the ConfigureScope callback).
There isn't really an easy way to set the root scope consistently, across all platforms, however. In our sample programs, this is done when initialising the Sentry options (e.g. here).
Reading the enricher code, it feels like other fields should also be set on the scope and not on the event itself, like sdk name/ version, release, distribution, environment, user id/ username.
Setting "" could work, but it will probably be flagged on Sentry UI as invalid field
The InstallationId-as-User.Id seems to be something that only makes sense on mobile (or at least only in apps where Global mode is true). It exists for session health metrics on devices with a persistent install identity. It's not the right semantic for a web server where "user" means the authenticated HTTP principal.
So a possible natural split is:
Use a root scope approach when IsGlobalModeEnabled (which is true on mobile, false on ASP.NET):
Mobile (global mode): set User.Id = InstallationId on the one global scope at init, remove it from the enricher → users can override freely
ASP.NET (non-global mode): don't touch the root scope at all → ScopeExtensions.Populate + HasUser() logic continues to work exactly as today
IsGlobalModeEnabled is the flag that says "this is a single-user client-side app" vs. "this is a multi-tenant server."
One side effect: on ASP.NET with SendDefaultPii = false, you currently still get User.Id = InstallationId from the enricher. Removing it from the enricher for non-global mode would stop that — which is probably the correct behavior for a web app (a server shouldn't be attaching a device GUID as the user identity and conflating reqests from multiple different users into a single pseudo session).
We should be able to initialise 'Global' session state when the options get passed into the Hub and the Scope manager first gets initialised:
Activity
jamescrosswell commentedon May 6, 2025
@lucas-zimerman that was done intentionally in this PR:
From what I can tell, we do want to have some default value for the
User.Id. This seems to be the case on iOS and Android, although I don't see any similar docs for PHP, Java or Python... so maybe it serves some special purpose on Mobile platforms.@bruno-garcia if
SendDefaultPiiis false, should we leave the Id blank (same as we do forIpAddressandUsername)?sentry-dotnet/src/Sentry/Internal/Enricher.cs
Lines 86 to 95 in ee62bb9
InstallationIdthat we create is considered PIIlucas-zimerman commentedon May 8, 2025
Out of curiosity, why not set
User.Id ??= _options.InstallationIdat the global scope when initializing the app? This way users will have this info when not set and will also be able to remove it if not requiredjamescrosswell commentedon May 9, 2025
Hi @lucas-zimerman ,
So I checked with Bruno. We intentionally set User.Id to a non-null value so that Session health metrics work on Mobile platforms. The installationId is just a GUID that we generate, so nothing super sensitive (it just let's us distinguish sessions from different users).
We could, as you suggest, do this when initialising the global/root scope for the app though (rather than in an enricher) so that you could overwrite this if you didn't care about session health metrics and you were worried about sending this.
lucas-zimerman commentedon May 9, 2025
On the app that I was looking, they are using manual session metrics, because they only want to monitor users after they login and when they logout, to stop the session manually, since it's an app for business, more than one person could be using the same app on the same session.
having the user.id set on the global scope would make it easier to clear it once and make it easier to actually know how many users are using the app, without counting the install ID
bruno-garcia commentedon May 9, 2025
Note that we can use
InstallationIdon Sessions while not setting it on the user scope. Sessions is detatched from errors data.Having the id set by default but allowing the users to reset to
nullonBeforeSendmakes sense thoughIn fact, BeforeSend should be the last thing that touches the event before we send it, to allow the user to have a full picture of what's being sent. And allow the user to make the mutations they want
lucas-zimerman commentedon May 12, 2025
SetBeforeSendis indeed a good option, but it also leaves native SDKs to set their Installaiton id that doesn't go towards C#BeforeSendsentry.native.android.dotnet
sentry.java.android.dotnet
for .NET BeforeSend I just added a check to see if user.id has
-and set it to null, but that logic wouldn't work for the native SDKs, if they even go towards .NET BeforeSendhopefully I won't need this filter on discover to count users lol
Workaround
apply the following rule to Sentry.io
[Remove] [UUIDs] from [$user.id]
linear commentedon Dec 3, 2025
NET-492
jamescrosswell commentedon Dec 5, 2025
@lucas-zimerman I took a look at this. Initially I was thinking to move the functionality from the enricher into the global scope.
Currently the enricher gets applied in two places:
SentryClient.CaptureTransaction: Here it's called immediately afterscope.Applyso if we stored the user id in the root scope, that would work fine.MainSentryEventProcessor.Process: This is the one that causes problems since it gets applied after the user does things like setting the user.id to null in a ConfigureScope callback. The event processor itself gets called fromSentryClient.DoSendEvent, however, and once again this happens after a call toscope.Apply.First idea
Since both locations where the enricher is applied are in code that runs after
scope.Apply, rather than using the main event processor to set the user id, we could instead set this in the root scope. That way it the SDK user does not override this, it will be applied as normal. If they do override it, then their value will take precedence (for example, they could set it to null via theConfigureScopecallback).There isn't really an easy way to set the root scope consistently, across all platforms, however. In our sample programs, this is done when initialising the Sentry options (e.g. here).
Initially I was thinking to put it here:
sentry-dotnet/src/Sentry/SentrySdk.cs
Line 184 in dadd070
... but that wouldn't work if this override was used to initialise the SDK:
sentry-dotnet/src/Sentry/SentrySdk.cs
Line 211 in dadd070
... and it wouldn't work for MAUI in any case (where this happens).
Alternative solution
Is it possible to set the user id to
""instead ofnullwhen no user is logged in? I think that would prevent this assignment:sentry-dotnet/src/Sentry/Internal/Enricher.cs
Line 95 in ee62bb9
And then in the options you could configure
options.IsEnvironmentUser = falseto prevent this assignment:sentry-dotnet/src/Sentry/Internal/Enricher.cs
Lines 88 to 91 in ee62bb9
lucas-zimerman commentedon Dec 5, 2025
Reading the enricher code, it feels like other fields should also be set on the scope and not on the event itself, like sdk name/ version, release, distribution, environment, user id/ username.
Setting "" could work, but it will probably be flagged on Sentry UI as invalid field
jamescrosswell commentedon Mar 18, 2026
OK revisiting this again.
The InstallationId-as-User.Id seems to be something that only makes sense on mobile (or at least only in apps where Global mode is true). It exists for session health metrics on devices with a persistent install identity. It's not the right semantic for a web server where "user" means the authenticated HTTP principal.
So a possible natural split is:
IsGlobalModeEnabled is the flag that says "this is a single-user client-side app" vs. "this is a multi-tenant server."
One side effect: on ASP.NET with SendDefaultPii = false, you currently still get User.Id = InstallationId from the enricher. Removing it from the enricher for non-global mode would stop that — which is probably the correct behavior for a web app (a server shouldn't be attaching a device GUID as the user identity and conflating reqests from multiple different users into a single pseudo session).
We should be able to initialise 'Global' session state when the options get passed into the Hub and the Scope manager first gets initialised:
sentry-dotnet/src/Sentry/Internal/Hub.cs
Lines 75 to 81 in f50b360
feat: User.Id can now be overriden (set to null) in Global mode