Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(node): Ensure express requests are properly handled #14850

Merged
merged 1 commit into from
Dec 30, 2024

Conversation

mydea
Copy link
Member

@mydea mydea commented Dec 30, 2024

Fixes #14847

After some digging, I figured out that the req.user handling on express is not working anymore, because apparently express does not mutate the actual http request object, but clones/forkes it (??) somehow. So since we now set the request in the SentryHttpInstrumentation generally, it would not pick up express-specific things anymore.

IMHO this is not great and we do not want this anymore in v9 anyhow, but it was the behavior before. This PR fixes this by setting the express request again on the isolation scope in an express middleware, which is registered by Sentry.setupExpressErrorHandler(app).

Note that we plan to change this behavior here: #14806 but I figured it still makes sense to fix this on develop first, so we have a proper history/tests for this. I will backport this to v8 too. Then, in PR #14806 I will remove the middleware again.

...extractedUser,
...event.user,
Copy link
Member Author

Choose a reason for hiding this comment

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

This is pretty weird and IMHO wrong before - if a user is set explicitly (e.g. via Sentry.setUser() this should always take precedence over this integration handling, I'd say.

@mydea mydea marked this pull request as ready for review December 30, 2024 09:18
Copy link
Member

@andreiborza andreiborza left a comment

Choose a reason for hiding this comment

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

LGTM

@mydea mydea merged commit 9cd0e8e into develop Dec 30, 2024
159 checks passed
@mydea mydea deleted the fn/express-request-handling branch December 30, 2024 13:31
mydea added a commit that referenced this pull request Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Express request.user is not used since 8.40.0
3 participants