Title: [Remix]: Sentry server instrumentation breaks loadContext parameter to handleRequest · Issue #8265 · getsentry/sentry-javascript · GitHub
Open Graph Title: [Remix]: Sentry server instrumentation breaks loadContext parameter to handleRequest · Issue #8265 · getsentry/sentry-javascript
X Title: [Remix]: Sentry server instrumentation breaks loadContext parameter to handleRequest · Issue #8265 · getsentry/sentry-javascript
Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using the latest SDK release https://github.com/...
Open Graph Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th...
X Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/8265
X: @github
Domain: github.com
IPv4 address: 140.82.113.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Remix]: Sentry server instrumentation breaks loadContext parameter to handleRequest","articleBody":"### Is there an existing issue for this?\n\n- [X] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues\n- [X] I have reviewed the documentation https://docs.sentry.io/\n- [X] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases\n\n### How do you use Sentry?\n\nSentry Saas (sentry.io)\n\n### Which SDK are you using?\n\n@sentry/remix\n\n### SDK Version\n\n^7.53.1\n\n### Framework Version\n\nRemix 1.16.1\n\n### Link to Sentry event\n\nhttps://support-budget.sentry.io/issues/4217820559/?project=4505236358037504&referrer=project-issue-stream\n\n### SDK Setup\n\nServer-side (these break the application):\r\n```ts\r\nSentry.init({\r\n\tdsn: ENV.SENTRY_DSN,\r\n\t// Set tracesSampleRate to 1.0 to capture 100%\r\n\t// of transactions for performance monitoring.\r\n\t// We recommend adjusting this value in production\r\n\ttracesSampleRate: 1.0,\r\n})\r\n```\r\n(Also reproduced with the Prisma integration on the server, but the issue occurs regardless of any integrations provided).\r\n\r\nClient-side (though testing has shown that the site runs ok with _only_ the client-side integration present, so client options are only included for completeness - they do not affect the bug):\r\n```ts\r\nSentry.init({\r\n\tdsn: ENV.SENTRY_DSN,\r\n\tintegrations: [\r\n\t\tnew Sentry.BrowserTracing({\r\n\t\t\t// Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled\r\n\t\t\ttracePropagationTargets: ['localhost'],\r\n\t\t\troutingInstrumentation: Sentry.remixRouterInstrumentation(\r\n\t\t\t\tuseEffect,\r\n\t\t\t\tuseLocation,\r\n\t\t\t\tuseMatches,\r\n\t\t\t),\r\n\t\t}),\r\n\t\t// Replay is only available in the client\r\n\t\tnew Sentry.Replay(),\r\n\t],\r\n\r\n\t// Set tracesSampleRate to 1.0 to capture 100%\r\n\t// of transactions for performance monitoring.\r\n\t// We recommend adjusting this value in production\r\n\ttracesSampleRate: 1.0,\r\n\r\n\t// Capture Replay for 10% of all sessions,\r\n\t// plus for 100% of sessions with an error\r\n\treplaysSessionSampleRate: 0.1,\r\n\treplaysOnErrorSampleRate: 1.0,\r\n})\r\n```\r\n\r\nI have created a sample repository with a reproduction of the problem, starting from Kent C Dodd's Epic Web Stack.\r\n\r\nRepository: https://github.com/dawnmist/sentry-remix-load-context-undefined.git\r\n\r\nBranches:\r\n- `main`: freshly created remix stack using `npx create-remix@latest --typescript --install --template epicweb-dev/epic-stack`\r\n- `sentry-remix-load-context-undefined`: added sentry instrumentation as per the document at: https://docs.sentry.io/platforms/javascript/guides/remix/\r\n- https://github.com/dawnmist/sentry-remix-load-context-undefined/pull/1/files - Draft PR showing the differences between those two branches.\r\n\r\nNote: the linked Sentry error is from my actual application when I was trying to trace what was going wrong, as I had tried to implement the nonce handling from the Epic Stack into my existing application then found that it completely broke. It took several hours and completely replacing my entry.server.ts file with a fresh one from that stack, then slowly adding changes back one at a time, to track the issue down to being due to the Sentry instrumentation. Once I had that, I then did a test using a fresh initialisation of the stack with only the sentry changes added to establish that it really was the addition of the sentry instrumentation that was causing the issue and to create a reproducible example I could provide for this report.\n\n### Steps to Reproduce\n\nWorking project prior to Sentry instrumentation:\r\n- Check out the main branch of the repository\r\n- Copy the `.env.example` file to `.env`\r\n- Run `npm run install`\r\n- Run `npm run dev` - you should get output like:\r\n```shell\r\n🔶 Mock server installed\r\n⚠️ Port 3000 is not available, using 3008 instead.\r\n🚀 We have liftoff!\r\nLocal: http://localhost:3008\r\nOn Your Network: http://192.168.1.20:3008\r\nPress Ctrl+C to stop\r\nApp server took 1.5s\r\n```\r\n- Load the url specified in the console log in a browser window\r\n==> you should see the \"EPIC STACK\" landing page.\r\n\r\nTo reproduce the Sentry problem:\r\n* Stop running the server\r\n* Check out the branch `sentry-remix-load-context-undefined`\r\n* Copy the `.env.example` file to `.env`, and update the (new to the branch) SENTRY_DSN variable to something you can use\r\n* Run `npm run install` to pick up the sentry libraries\r\n* Run `npm run dev` - you should get the same output as before\r\n* Load the url specified in the console log in a browser window\r\n==> The page throws the error:\r\n```\r\nUnexpected Server Error\r\n\r\nTypeError: Cannot read properties of undefined (reading 'cspNonce')\r\n```\r\n\r\nTesting variations locally has shown that if either of the modifications to `./app/entry.server.ts` (Sentry.init on the remix server) or `./server/index.ts` (using wrapExpressCreateRequestHandler) are present the remix server will not receive the value created for the `loadContext` parameter to the `handleRequest` function in `./app/entry.server.ts` file. The client side Sentry.init does not affect the issue at all.\n\n### Expected Result\n\nThe function `handleRequest` in `./app/entry.server.ts` should be properly receiving the context information that is being set in the express server in `./server/index.ts` regardless of whether Sentry instrumentation has been applied to the server.\n\n### Actual Result\n\nIf the server has either or both of the `Sentry.init` on the `./app/entry.server.ts` file OR `wrapExpressCreateRequestHandler` used in an express server that runs the remix server, the context being set with the `getLoadContext` option to the `createRequestHandler` function is not passed through to the remix application in the `handleRequest` function's `loadContext` parameter.","author":{"url":"https://github.com/dawnmist","@type":"Person","name":"dawnmist"},"datePublished":"2023-05-31T14:34:46Z","url":"https://github.com/getsentry/sentry-javascript/issues/8265"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:3e48464e-11cf-541f-a8de-0c55573804db |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C300:1C5C1D:23AB93C:2FCA3B0:6B044C1B |
| html-safe-nonce | 399b8d4ed1b0982b1eeda66f256954927c10977c58ef7cf8df1d06408315415e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMzAwOjFDNUMxRDoyM0FCOTNDOjJGQ0EzQjA6NkIwNDRDMUIiLCJ2aXNpdG9yX2lkIjoiMTkxMjkyNzYwODc5MDg2Mjg3NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 26336ae2f05d9c109e2c68fb1e6ef873f27a46430b1e408d78e25b5674138519 |
| hovercard-subject-tag | issue:1734378178 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-javascript/8265/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0b79f4f3121cd280e8c651c9095c460fde460aea1d73bb129d590e972638285e/getsentry/sentry-javascript/issues/8265 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0b79f4f3121cd280e8c651c9095c460fde460aea1d73bb129d590e972638285e/getsentry/sentry-javascript/issues/8265 |
| og:image:alt | Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dawnmist |
| hostname | github.com |
| expected-hostname | github.com |
| None | 002aa6b95ffa730b0aec436a5c383f536ad677284e60056037fb120afe37b730 |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-javascript git https://github.com/getsentry/sentry-javascript.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 3328572 |
| octolytics-dimension-repository_nwo | getsentry/sentry-javascript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3328572 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-javascript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 059f24c781e3a0d7df3f27a97da0e93fab06ae39 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width