Skip to content

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

@mustafaakin

Description

@mustafaakin

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions