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

Mobile: User.Other is included in managed errors but not native ones #3340

Open
bruno-garcia opened this issue Apr 30, 2024 · 2 comments
Open
Labels

Comments

@bruno-garcia
Copy link
Member

When using the SDK's C# API to change the Scope, we're able to pass down some fields to the native layer.
So if a crash is caused by Java/Kotlin/Objective-C/Swift/C/C++ etc, it'll include User top level firleds and tags.

How it works: Setting the user in C# triggers the ScopeObserver:

public SentryUser User
{
get => _user ??= new SentryUser
{
PropertyChanged = UserChanged
};
set
{
if (_user != value)
{
_user = value;
if (_user is not null)
{
_user.PropertyChanged = UserChanged;
}
UserChanged.Invoke(_user);
}
}
}

So on iOS for example, we'll set the user as such:

public void SetUser(SentryUser? user)
{
try
{
var u = user?.ToCocoaUser();
SentryCocoaSdk.ConfigureScope(scope => scope.SetUser(u));
}
finally
{
_innerObserver?.SetUser(user);
}
}

On Android:

public void SetUser(SentryUser? user)
{
try
{
var u = user?.ToJavaUser();
JavaSdk.Sentry.SetUser(u);
}
finally
{
_innerObserver?.SetUser(user);
}

And Native ([sentry-native](https://github.com/getsentry/sentry-native)):

public override void SetUserImpl(SentryUser user)
{
// see https://develop.sentry.dev/sdk/event-payloads/user/
var cUser = C.sentry_value_new_object();
C.SetValueIfNotNull(cUser, "id", user.Id);
C.SetValueIfNotNull(cUser, "username", user.Username);
C.SetValueIfNotNull(cUser, "email", user.Email);
C.SetValueIfNotNull(cUser, "ip_address", user.IpAddress);
C.sentry_set_user(cUser);
}

But we don't include everything, and that's not documented anywhere it seems.

For example, we don't sync down to native User.Other. And this can be a pitfall to customers.
We need to at least clearly document this, or expand scope sync for this field.

@bruno-garcia
Copy link
Member Author

came from a customer, cc @JLuse ^

@bitsandfoxes
Copy link
Contributor

bitsandfoxes commented May 8, 2024

Documenting the pitfall won't fix bad UX. And looking at what sentry-native allows us to do we should sync down Other.
Don't hang me for my native code but something like this should work:

sentry_value_t user = sentry_value_new_object();
sentry_value_t other = sentry_value_new_object()
sentry_value_set_by_key(other, "my_key", sentry_value_new_string("my_value"));
// add all the stuff
sentry_value_set_by_key(user, "contexts", other);

sentry_set_user(user);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

No branches or pull requests

2 participants