sentry-java
sentry-java copied to clipboard
When using Sentry.setUser, others are put into a map instead of high level values
Problem Statement
I'm using a custom-built User with additional properties.
Sentry.setUser(
User().apply {
this.email = email
this.id = membership.user_id
this.others = mapOf(
"account" to membership.account_name,
"accountId" to membership.account_id,
"domain" to membership.account_domain,
"role" to membership.account_name
)
}
)
However, in Sentry UI, it's shown like:
email : ....
id : .....
other = {
account: Corp,
accountId: bf06170b-1934-41c4-9676-8c310117afe0,
domain: corp-trial,
role: Corp
}
However, when I use JS SDK to set custom objects, it puts them to the high level User object as follows:
email : ....
id : .....
account: Corp,
accountId: bf06170b-1934-41c4-9676-8c310117afe0,
domain: corp-trial,
role: Corp
Do you think it's worth a change? The User class is also final, and I cannot override it, unfortunately.
Solution Brainstorm
Instead of the following code in io.sentry.protocol.User, we can iterate the key values of other and put them to the root user object instead.
if (other != null) {
writer.name(JsonKeys.OTHER).value(logger, other);
}
Thanks @mustafaakin for raising this. We'll have a chat about this internally and update here once we know more.
@mustafaakin we have a PR up for changing the behaviour. Once the change lands you should see your custom user properties show up the same way you are in JS.
Wonderful. Thanks for listening & implementing it.
It will land in the next release.