-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Setup for Remix with custom express server #16758
-
What's the ideal setup for Sentry within a remix app with a custom express server? I am using "@sentry/remix": "9.24.0"
and "@sentry/node": "9.24.0"
Original setup
Before I had the custom express server, I had the @sentry/remix
package set up in both entry.client
and entry.server
which seemed to work well.
New setup
Now that I have the custom express server, I want to have Sentry still catch errors from custom middleware or other things generated within the express server. I added a instrument.ts
file with a Sentry.init
from @sentry/node
and changed my start
script in package.json
to npx tsx --import server/utils/instrument.ts server/index.ts",
. I also added Sentry.setupExpressErrorHandler(app);
to the end of my server index file.
This seems correct except that I found the Sentry.init
in my entry.server
is not working (i.e. if I try to log something in a beforeSend
it doesn't fire). I found that the Sentry.init
in my instrument.ts
file was the one logging to sentry for my remix server-side errors and that it basically overrode my entry.server
one.
So, I deleted my entry.server
Sentry.init.
Can't get user attribution to work
But, I'm now having trouble with user attribution (just for the server). Previously, I was using
Sentry.withIsolationScope(async (scope) => {
scope.setUser(...)
}
within my handleRequest
and handleDataRequest
function within entry.server
, but I found these no longer worked...I figured that I wanted user attribution on the express server as well anyway, so I got rid of this and created a custom middleware that just calls Sentry.setUser
. This still doesn't work though.
Despite better judgement, I attempted to change the import in my instrument.ts
file to @sentry/remix
and now my user attribution suddenly works! However, I found that in a non-dev instance (i.e. npm run start
), returning from a remix action hangs indefinitely! I'm assuming this is because sentry doesn't know it's in express land and doesn't return the response correctly...
For now, I've gone back to using @sentry/node
on my instrument
file, but none of the user attribution is working. Any advice on how to set this up correctly would be appreciated.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
hey, can you clarify what did not work with the regular remix setup you had (in entry.server) once you started to use a custom express server? Were express errors/middlewares not captured?
Beta Was this translation helpful? Give feedback.