Setup for Remix with custom express server #16758
Unanswered
crestwood204
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
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 bothentry.client
andentry.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 aSentry.init
from@sentry/node
and changed mystart
script inpackage.json
tonpx tsx --import server/utils/instrument.ts server/index.ts",
. I also addedSentry.setupExpressErrorHandler(app);
to the end of my server index file.This seems correct except that I found the
Sentry.init
in myentry.server
is not working (i.e. if I try to log something in abeforeSend
it doesn't fire). I found that theSentry.init
in myinstrument.ts
file was the one logging to sentry for my remix server-side errors and that it basically overrode myentry.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
within my
handleRequest
andhandleDataRequest
function withinentry.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 callsSentry.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 myinstrument
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