Skip to content

update user context to mark 'data' keys#90993

Merged
JoshuaMoelans merged 2 commits intomasterfrom
joshua/fix/visualizing_user_context_data
May 7, 2025
Merged

update user context to mark 'data' keys#90993
JoshuaMoelans merged 2 commits intomasterfrom
joshua/fix/visualizing_user_context_data

Conversation

@JoshuaMoelans
Copy link
Copy Markdown
Member

@JoshuaMoelans JoshuaMoelans commented May 6, 2025

Fixes getsentry/sentry-native#1225

For User Context, SDKs are expected to send the default fields in lowercase (e.g. username, email, ip_address, ...) which get rendered nicely (Username, Email, IP Address, ...) in the Sentry UI. But, when they send us a key likeEmail this will look the same in the UI (but will not be treated the same). Hence I propose this fix which marks keys from the user context's data section as data.X.

(this is just a suggestion; maybe there is a cleaner way to mark these items as "data" that has less visual clutter, so I'm open to feedback 😄 )

"user": {
    "id": "42",
    "email": "john.doe@email.com",
    "ip_address": "127.0.0.1",
    "username": "John Doe",
    "sentry_user": "id:42",
    "data": {
        "Email": "jane.doe@email.com",
        "Username": "Jane Doe"
    }
}

currently rendered as

image

newly rendered as
image

@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label May 6, 2025
@codecov
Copy link
Copy Markdown

codecov bot commented May 6, 2025

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
10291 1 10290 9
View the top 1 failed test(s) by shortest run time
UserContext returns values and according to the parameters
Stack Traces | 0.019s run time
Error: expect(received).toEqual(expected) // deep equality

- Expected  - 2
+ Received  + 2

@@ -33,15 +33,15 @@
      "value": "San Francisco, California, United States (US)",
    },
    Object {
      "key": "extra_data",
      "meta": undefined,
-     "subject": "extra_data",
+     "subject": "data.extra_data",
      "value": "something",
    },
    Object {
      "key": "unknown_key",
      "meta": undefined,
-     "subject": "unknown_key",
+     "subject": "data.unknown_key",
      "value": 123,
    },
  ]
    at Object.<anonymous> (.../contexts/knownContext/user.spec.tsx:37:9)
    at Promise.then.completed (.../jest-circus/build/utils.js:298:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (.../jest-circus/build/utils.js:231:10)
    at _callCircusTest (.../jest-circus/build/run.js:316:40)
    at processTicksAndRejections (node:internal/process/task_queues:105:5)
    at _runTest (.../jest-circus/build/run.js:252:3)
    at _runTestsForDescribeBlock (.../jest-circus/build/run.js:126:9)
    at _runTestsForDescribeBlock (.../jest-circus/build/run.js:121:9)
    at run (.../jest-circus/build/run.js:71:3)
    at runAndTransformResultsToJestFormat (.../build/legacy-code-todo-rewrite/jestAdapterInit.js:122:21)
    at jestAdapter (.../build/legacy-code-todo-rewrite/jestAdapter.js:79:19)
    at runTestInternal (.../jest-runner/build/runTest.js:367:16)
    at runTest (.../jest-runner/build/runTest.js:444:34)
    at Object.worker (.../jest-runner/build/testWorker.js:106:12)

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@JoshuaMoelans JoshuaMoelans marked this pull request as ready for review May 6, 2025 10:42
@JoshuaMoelans JoshuaMoelans requested a review from a team as a code owner May 6, 2025 10:42
Copy link
Copy Markdown
Member

@leeandher leeandher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense! thanks for the fix 🚀

@JoshuaMoelans JoshuaMoelans merged commit 95a9152 into master May 7, 2025
45 checks passed
@JoshuaMoelans JoshuaMoelans deleted the joshua/fix/visualizing_user_context_data branch May 7, 2025 09:45
JoshuaMoelans added a commit to getsentry/sentry-docs that referenced this pull request May 8, 2025
<!-- Use this checklist to make sure your PR is ready for merge. You may
delete any sections you don't need. -->

[Vercel
Preview](https://develop-docs-bmq9r90m3.sentry.dev/sdk/data-model/event-payloads/user/)

## DESCRIBE YOUR PR
Related to getsentry/sentry#90993 , where we
added the prefix `data.` to all unknown User Context keys, making them
stand out in the UI.

It was confusing to some users that the UI showed the User data in a
"prettified" manner, not matching the expected keys sent from the SDKs,
so I'm adding some warnings/notes to the develop docs to clear this up.

## IS YOUR CHANGE URGENT?  

Help us prioritize incoming PRs by letting us know when the change needs
to go live.
- [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE -->
- [ ] Other deadline: <!-- ENTER DATE HERE -->
- [x] None: Not urgent, can wait up to 1 week+

## SLA

- Teamwork makes the dream work, so please add a reviewer to your PRs.
- Please give the docs team up to 1 week to review your PR unless you've
added an urgent due date to it.
Thanks in advance for your help!

## PRE-MERGE CHECKLIST

*Make sure you've checked the following before merging your changes:*

- [ ] Checked Vercel preview for correctness, including links
- [ ] PR was reviewed and approved by any necessary SMEs (subject matter
experts)
- [ ] PR was reviewed and approved by a member of the [Sentry docs
team](https://github.com/orgs/getsentry/teams/docs)

---------

Co-authored-by: Karl Heinz Struggl <kahest@users.noreply.github.com>
Co-authored-by: Alex Krawiec <alex.krawiec@sentry.io>
andrewshie-sentry pushed a commit that referenced this pull request May 12, 2025
Fixes getsentry/sentry-native#1225

For User Context, SDKs are
[expected](https://develop.sentry.dev/sdk/data-model/event-payloads/user/)
to send the default fields in lowercase (e.g. `username`, `email`,
`ip_address`, ...) which get rendered nicely (`Username`, `Email`, `IP
Address`, ...) in the Sentry UI. But, when they send us a key
like`Email` this will look the same in the UI (but will not be treated
the same). Hence I propose this fix which marks keys from the user
context's `data` section as `data.X`.

(this is just a suggestion; maybe there is a cleaner way to mark these
items as "data" that has less visual clutter, so I'm open to feedback 😄
)

```json
"user": {
    "id": "42",
    "email": "john.doe@email.com",
    "ip_address": "127.0.0.1",
    "username": "John Doe",
    "sentry_user": "id:42",
    "data": {
        "Email": "jane.doe@email.com",
        "Username": "Jane Doe"
    }
}
```
currently rendered as 


![image](https://github.com/user-attachments/assets/caef6671-e604-44fd-ad53-a1796f0f3a4b)

newly rendered as 

![image](https://github.com/user-attachments/assets/48226087-b77f-4bcb-969c-331942198759)
@github-actions github-actions bot locked and limited conversation to collaborators May 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

User Context is Case Sensitive

2 participants