Correct way to setUser in node sdk?

Hello! I recently added Sentry.setUser in our nodejs integration, and it caused user information to leak across requests into user requests that don’t belong to the current user, likely due to concurrent handling of requests. We’ve removed it for now, but we would like to add this information back.

Based on Add Context for Node.js | Sentry Documentation, I can’t figure out what the correct way is to do this.

  1. Sentry.configureScope(scope => scope.setUser(… seems like it could be right, but now i’m worried that’s going to set a configureScope callback globally, and I’ll be back to the same problem.
  2. I’ve also seen references in sentry sdk code to Sentry.getCurrentHub().getScope(). Would that be better?
  3. Maybe this isn’t handled automatically at all?

What’s the correct way to set user data for the current scope/operation, such that it won’t leak across requests?

Thanks,

Ben

Have you figured this out? I have the exact same question.

Sentry.getCurrentHub().getScope() also causes concurrency issues.
I’ve been using the bellow code for a while but users are still logged incorrectly.

Sentry.getCurrentHub().configureScope((scope) => { 
    scope.setUser({ id: oid, username: upn, email: upn, ip_address: ipaddr }); 
});

If I make the first request the first user is recorded. Then if I make a new request with no user info, then the second request still remains associated with first user.