getsentry / sentry

Developer-first error tracking and performance monitoring
https://sentry.io
Other
37.71k stars 4.05k forks source link

User Doesn't Appear at Top #72684

Closed scefali closed 1 month ago

scefali commented 1 month ago

Environment

SaaS (https://sentry.io/)

Steps to Reproduce

I am trying to set the user for an API route Next.js for an application. Following the instructions here.

Here is my code:

import { getAuth as clerkGetAuth } from "@clerk/nextjs/server";
import * as Sentry from "@sentry/nextjs";

export function getAuth(req, options) {
  const auth = clerkGetAuth(req, options);
  if (auth) {
    Sentry.setUser({
      userId: auth.userId,
      orgSlug: auth.orgSlug,
      orgRole: auth.orgRole,
      orgId: auth.orgId
    });
  }
  return auth;
}

Expected Result

User information should show up in event highlights.

Actual Result

User information shows up in context instead:

Screenshot 2024-06-13 at 10 00 01 PM Screenshot 2024-06-13 at 10 00 09 PM

Product Area

Issues

Link

https://builtrightco.sentry.io/issues/5486316096/?project=4507410872139776

DSN

No response

Version

No response

getsantry[bot] commented 1 month ago

Assigning to @getsentry/support for routing ⏲️

getsantry[bot] commented 1 month ago

Routing to @getsentry/product-owners-issues for triage ⏲️

leeandher commented 1 month ago

Hey @scefali! (miss you on the team 🫶)

The event highlights get pre-populated with some defaults based on the project (like User.Email) but other properties you added won't be highlighted dynamically. Anything in 'Tags' or 'Contexts' can be highlighted.

You'll need to manually add them by using the 'Edit' button just above the highlights. Going forward, those should appear at the top of every issue for the project! 👍

scefali commented 1 month ago

@leeandher miss you guys as well!

The only thing that's a bit annoying is that I don't think it registers these contexts as user tags because I have 0 users: Screenshot 2024-06-18 at 4 51 10 AM

Does setting the user in Node behave differently than on the backend? Or is it because I set id instead of userId? Editing the event highlights made it appear a the top at least, nifty feature! Nice work on that btw

malwilley commented 1 month ago

@scefali nice to see you here! Yeah I think it's because you need to want Sentry.setUser({ id: auth.userId, ... }) instead of setting userId. According to the docs, it needs one of id, username, email, or ip_address to work the way you'd expect.

leeandher commented 1 month ago

Yeah it's a bit obscure but context items aren't searchable the way tags are so you won't be able to query them. When ingesting events, Sentry will promote some context to searchable tags (e.g. user.id, brower.version, etc.) but the rest of the context will remain not searchable.

The setUser(...) operation in the SDK is kind of an alias for setContext('user', ...) so your custom user keys are not searchable. You'll have to use setTag instead.

If you use id instead of userId though, that would probably get at least that ID promoted to a tag by default! Even if you'll have to do it manually for orgSlug, orgRole etc.

scefali commented 1 month ago

@malwilley @leeandher Thanks guys! I'm sure I'll be posting issues here and there these days :D