Title: Unable to use Sentry NextJS integration with middleware on Cloudflare Pages · Issue #8935 · getsentry/sentry-javascript · GitHub
Open Graph Title: Unable to use Sentry NextJS integration with middleware on Cloudflare Pages · Issue #8935 · getsentry/sentry-javascript
X Title: Unable to use Sentry NextJS integration with middleware on Cloudflare Pages · Issue #8935 · 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/8935
X: @github
Domain: github.com
IPv4 address: 140.82.112.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Unable to use Sentry NextJS integration with middleware on Cloudflare Pages","articleBody":"### Is there an existing issue for this?\r\n\r\n- [X] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues\r\n- [X] I have reviewed the documentation https://docs.sentry.io/\r\n- [X] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases\r\n\r\n### How do you use Sentry?\r\n\r\nSelf-hosted/on-premise\r\n\r\n### Which SDK are you using?\r\n\r\n@sentry/nextjs\r\n\r\n### SDK Version\r\n\r\n7.66.0\r\n\r\n### Framework Version\r\n\r\n7.66.0\r\n\r\n### Link to Sentry event\r\n\r\n_No response_\r\n\r\n### SDK Setup\r\n\r\n_No response_\r\n\r\n### Steps to Reproduce\r\n\r\nHi,\r\nProbably this is not much of a Sentry issue, but popping this here in case you know any workaround for this, or maybe this can be fixed on your side.\r\n\r\nCloudflare workers runtime (not sure if any other serverless runtimes do though) has an issue with running Sentry Next.js integration along with middleware in a project. As the dev of next-on-pages said, the issue here is that Sentry causes \"the generation of a `randomUUID` at the top level of the middleware function file.\"\r\n\r\nIssue on next-on-pages with explanation: https://github.com/cloudflare/next-on-pages/issues/420#issuecomment-1692103962\r\n\r\nSo maybe Sentry can avoid calling `randomUUID` at the top level? I don't have much insight into Sentry internals or how Next.js integration works, or even why this doesn't work with middleware specifically but maybe you can shed some light on how this can be resolved.\r\n\r\nRepro (repo: https://github.com/Enalmada/next-apps-for-testing/pull/1):\r\n1. Create a NextJS app project and initialize Sentry\r\n2. Create a middleware file and deploy using next-on-pages:\r\n\r\n```typescript\r\nimport { NextResponse } from 'next/server'\r\nimport type { NextRequest } from 'next/server'\r\n \r\nexport function middleware(request: NextRequest) {\r\n return NextResponse.next();\r\n}\r\n```\r\n\r\nTo run a Next.js project in Cloudflare worker env, you can do so locally:\r\n```\r\nnpx @cloudflare/next-on-pages@1 \r\nnpx wrangler pages dev .vercel/output/static\r\n```\r\n\r\n### Expected Result\r\n\r\nProject works\r\n\r\n### Actual Result\r\n\r\n```\r\nA promise rejection was handled asynchronously. This warning occurs when attaching a catch handler to a promise after it rejected. (rejection #1)\r\nError: Some functionality, such as asynchronous I/O, timeouts, and generating random values, can only be performed while handling a request.\r\n at W (__next-on-pages-dist__/functions/src/middleware.func.js:9:28306)\r\n at Wt (__next-on-pages-dist__/functions/src/middleware.func.js:9:39049)\r\n at new se (__next-on-pages-dist__/functions/src/middleware.func.js:9:33435)\r\n at new ct (__next-on-pages-dist__/functions/src/middleware.func.js:9:39120)\r\n at Kt (__next-on-pages-dist__/functions/src/middleware.func.js:9:42593)\r\n at J (__next-on-pages-dist__/functions/src/middleware.func.js:9:42523)\r\n at Fr (__next-on-pages-dist__/functions/src/middleware.func.js:9:43898)\r\n at wi (__next-on-pages-dist__/functions/src/middleware.func.js:13:21539)\r\n at 7819 (__next-on-pages-dist__/functions/src/middleware.func.js:13:22028)\r\n at _ (__next-on-pages-dist__/functions/src/middleware.func.js:1:729) {\r\n stack: Error: Some functionality, such as asynchronous I/…es-dist__/functions/src/middleware.func.js:1:729),\r\n message: Some functionality, such as asynchronous I/O, time…, can only be performed while handling a request.\r\n}\r\n```","author":{"url":"https://github.com/blitss","@type":"Person","name":"blitss"},"datePublished":"2023-09-03T15:07:51Z","url":"https://github.com/getsentry/sentry-javascript/issues/8935"}
| 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:d4be9d1f-970b-510f-96c2-e0cdecbe4a95 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 973C:3C6C12:43CB9B:5D91DE:6B049EF9 |
| html-safe-nonce | 95396acb4b6b146929eb7a9b2cbb00aaceda6627519000320d3fc63d2f42b974 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NzNDOjNDNkMxMjo0M0NCOUI6NUQ5MURFOjZCMDQ5RUY5IiwidmlzaXRvcl9pZCI6IjQwNTA5MDk5NTU5MDg0NzY2NjUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 4b411fba4d431cac26996e8dc83a116719560f20f68e6fdfc40d58f5d4912cc9 |
| hovercard-subject-tag | issue:1879131654 |
| 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/8935/issue_layout |
| twitter:image | https://opengraph.githubassets.com/da48f40c5d804f73f20592b64f93520bf30e27a937e38464d8497cf06a4ff9b9/getsentry/sentry-javascript/issues/8935 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/da48f40c5d804f73f20592b64f93520bf30e27a937e38464d8497cf06a4ff9b9/getsentry/sentry-javascript/issues/8935 |
| 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 | blitss |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9784b6f42e2d5eac4e394fa88cad134c0dc5b6662b4ff2787a1ed1ef5a96331d |
| 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 | 3fd14143b75b2af7b76bbd23b069867d091adfcc |
| 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