Skip to content

How to set the user on server side with @sentry/nextjs? #8777

Closed Answered by AbhiPrasad
sneko asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @sneko

The nextjs sdk if set up with automatic instrumentation should be isolating request context for api routes! You shouldn't have to setup anything up or use Sentry.runWithAsyncContext unless you are using a custom server.

Using middleware like you mentioned doesn't actually work, because in Next.js middleware (and any other edge runtime features) basically runs in its own process. Any context you give to Sentry in middleware is only available for things happening inside the middleware.

You'll have to add a helper that you then wrap every api route/route handler with. See vercel/next.js#15286 (comment). There is no way to do this in a central place with the Next.js framework - it'…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@sneko
Comment options

Answer selected by sneko
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants