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

When using Sentry.setUser, others are put into a map instead of high level values

Open mustafaakin opened this issue 2 years ago • 1 comments

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);
}

mustafaakin avatar Sep 13 '22 09:09 mustafaakin

Thanks @mustafaakin for raising this. We'll have a chat about this internally and update here once we know more.

adinauer avatar Sep 13 '22 13:09 adinauer

@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.

adinauer avatar Sep 26 '22 12:09 adinauer

Wonderful. Thanks for listening & implementing it.

mustafaakin avatar Sep 26 '22 12:09 mustafaakin

It will land in the next release.

adinauer avatar Sep 29 '22 12:09 adinauer