Skip to content

wrapExpressCreateRequestHandler not working in Remix with Express adapter #5742

@shrzaf

Description

@shrzaf

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/remix

SDK Version

7.12.1

Framework Version

Remix 1.7.0

Link to Sentry event

No response

Steps to Reproduce

  1. Create new Remix app (with custom Express server and TypeScript):
$ npx create-remix@latest
Need to install the following packages:
  create-remix@latest
Ok to proceed? (y) y
? Where would you like to create your app? remix-express
? What type of app do you want to create? Just the basics
? Where do you want to deploy? Choose Remix App Server if you're unsure; it's easy to change deployment
targets. Express Server
? TypeScript or JavaScript? TypeScript
  1. Install @sentry/remix:
npm install @sentry/remix
  1. Configure Sentry according to the official documentation. Enable Sentry debug logging in entry.server.tsx for good measure.

  2. Throw an error from any loader, start the app (either dev or prod would do) and open the corresponding route in a browser.

Expected Result

The thrown error should be sent to sentry.io and appear in the Web UI.

Actual Result

No error is sent to sentry.io and no Sentry activity is logged:

$ npm run dev

> dev
> remix build && run-p "dev:*"

Building Remix app in production mode...
Built in 205ms

> dev:node
> cross-env NODE_ENV=development nodemon ./server.js --watch ./server.js


> dev:remix
> remix watch

[nodemon] 2.0.19
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): server.js
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node ./server.js`
Express server listening on port 3000
Watching Remix app in development mode...
💿 Built in 389ms
Sentry Logger [log]: Integration installed: InboundFilters
Sentry Logger [log]: Integration installed: FunctionToString
Sentry Logger [log]: Integration installed: ContextLines
Sentry Logger [log]: Integration installed: Console
Sentry Logger [log]: Integration installed: Http
Sentry Logger [log]: Integration installed: OnUncaughtException
Sentry Logger [log]: Integration installed: OnUnhandledRejection
Sentry Logger [log]: Integration installed: LinkedErrors
Sentry Logger [log]: Integration installed: Context
There was an error running the data loader for route routes/error
Error: Fehler!!!
    at loader (/path/to/remix-express/app/routes/error.tsx:6:11)
    at /path/to/remix-express/node_modules/@sentry/remix/cjs/utils/instrumentServer.js:123:21
    at Object.callRouteLoader (/path/to/remix-express/node_modules/@remix-run/server-runtime/dist/data.js:77:20)
    at /path/to/remix-express/node_modules/@remix-run/server-runtime/dist/server.js:261:113
    at Array.map (<anonymous>)
    at handleDocumentRequest (/path/to/remix-express/node_modules/@remix-run/server-runtime/dist/server.js:261:67)
    at requestHandler (/path/to/remix-express/node_modules/@remix-run/server-runtime/dist/server.js:49:24)
    at /path/to/remix-express/node_modules/@sentry/remix/cjs/utils/instrumentServer.js:330:35
    at bound (node:domain:421:15)
    at runBound (node:domain:432:12)
GET /error 500 - - 74.239 ms

This started happening with the introduction of wrapExpressCreateRequestHandler in 7.11.0. Following the above-mentioned steps with 7.10.0 (minus wrapping createRquestHandler with wrapExpressCreateRequestHandler) would correctly send the error to sentry.io:

$ npm run dev

> dev
> remix build && run-p "dev:*"

Building Remix app in production mode...
Built in 169ms

> dev:node
> cross-env NODE_ENV=development nodemon ./server.js --watch ./server.js


> dev:remix
> remix watch

[nodemon] 2.0.19
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): server.js
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node ./server.js`
Express server listening on port 3000
Watching Remix app in development mode...
💿 Built in 177ms
Sentry Logger [log]: Integration installed: InboundFilters
Sentry Logger [log]: Integration installed: FunctionToString
Sentry Logger [log]: Integration installed: ContextLines
Sentry Logger [log]: Integration installed: Console
Sentry Logger [log]: Integration installed: Http
Sentry Logger [log]: Integration installed: OnUncaughtException
Sentry Logger [log]: Integration installed: OnUnhandledRejection
Sentry Logger [log]: Integration installed: LinkedErrors
Sentry Logger [log]: [Tracing] Starting 'remix.server.loader' span on transaction 'routes/error' (a2516edfe3d1ab7c).
There was an error running the data loader for route routes/error
Sentry Logger [log]: [Tracing] Starting 'remix.server.documentRequest' span on transaction 'routes/error' (a2516edfe3d1ab7c).
Error: Fehler!!!
    at loader (/path/to/remix-express/app/routes/error.tsx:6:11)
    at /path/to/remix-express/node_modules/@sentry/remix/cjs/utils/instrumentServer.js:140:26
    at Object.callRouteLoader (/path/to/remix-express/node_modules/@remix-run/server-runtime/dist/data.js:77:20)
    at /path/to/remix-express/node_modules/@remix-run/server-runtime/dist/server.js:261:113
    at Array.map (<anonymous>)
    at handleDocumentRequest (/path/to/remix-express/node_modules/@remix-run/server-runtime/dist/server.js:261:67)
    at requestHandler (/path/to/remix-express/node_modules/@remix-run/server-runtime/dist/server.js:49:24)
    at /path/to/remix-express/node_modules/@sentry/remix/cjs/utils/instrumentServer.js:288:41
    at /path/to/remix-express/node_modules/@remix-run/express/dist/server.js:39:28
    at /path/to/remix-express/server.js:37:11
Sentry Logger [log]: [Tracing] Finishing 'remix.server.documentRequest' span on transaction 'routes/error' (a2516edfe3d1ab7c).
Sentry Logger [log]: [Tracing] Discarding transaction because its trace was not chosen to be sampled.
GET /error 500 - - 124.865 ms



Metadata

Metadata

Assignees

Labels

Package: remixIssues related to the Sentry Remix SDK

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions