Title: Support Next.js on Cloudflare Workers (OpenNext) · Issue #14931 · getsentry/sentry-javascript · GitHub
Open Graph Title: Support Next.js on Cloudflare Workers (OpenNext) · Issue #14931 · getsentry/sentry-javascript
X Title: Support Next.js on Cloudflare Workers (OpenNext) · Issue #14931 · 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/14931
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Support Next.js on Cloudflare Workers (OpenNext)","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/nextjs\n\n### SDK Version\n\n8.47.0\n\n### Framework Version\n\nnext@14.2.4\n\n### Link to Sentry event\n\n_No response_\n\n### Reproduction Example/SDK Setup\n\n# Configs\n## next.config.mjs\n```mjs\nimport { withSentryConfig } from '@sentry/nextjs';\n/** @type {import('next').NextConfig} */\nconst nextConfig = {\n experimental: {\n instrumentationHook: true,\n },\n reactStrictMode: true,\n async headers() {\n return MY_HEADER_CONFIGS\n },\n};\n\nexport default withSentryConfig(nextConfig, {\n org: 'MY_ORG',\n project: 'MY_PROJECT',\n silent: !process.env.CI,\n widenClientFileUpload: true,\n reactComponentAnnotation: {\n enabled: true,\n },\n tunnelRoute: '/monitoring',\n hideSourceMaps: true,\n disableLogger: false,\n automaticVercelMonitors: true,\n});\n```\n\n## instrumentation.ts\n```typescript\nimport * as Sentry from '@sentry/nextjs';\n\nexport async function register() {\n if (process.env.NEXT_RUNTIME === 'nodejs') {\n await import('../sentry.server.config');\n }\n\n if (process.env.NEXT_RUNTIME === 'edge') {\n await import('../sentry.edge.config');\n }\n}\n\nexport const onRequestError = Sentry.captureRequestError;\n```\n\n## sentry.edge.config.ts\n```typescript\nimport * as Sentry from '@sentry/nextjs';\n\nSentry.init({\n environment: process.env.NEXT_PUBLIC_SENTRY_ENV,\n dsn: 'MY_DSN',\n tracesSampleRate: 1,\n debug: true,\n});\n```\n\n## deploy-action.yaml\n```yaml\nname: Deploy\n\non:\n push:\n branches-ignore:\n - master\n workflow_dispatch:\n\njobs:\n deploy:\n runs-on: ubuntu-latest\n env:\n NEXT_PUBLIC_SENTRY_ENV: \"preview\"\n SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}\n permissions:\n contents: \"read\"\n id-token: \"write\"\n steps:\n - uses: \"actions/checkout@v4\"\n - uses: actions/setup-node@v4\n with:\n node-version: ${{ matrix.node-version }}\n - run: npm ci\n - name: Build\n run: npx -w MY_WORKSPACE @cloudflare/next-on-pages --disableChunksDedup\n - name: Publish to Cloudflare Pages\n uses: cloudflare/wrangler-action@v3\n with:\n apiToken: ${{ secrets.CF_API_TOKEN_V2 }}\n accountId: ${{ secrets.CF_ACCOUNT_ID }}\n command: pages deploy MY_WORKSPACE_DIR/.vercel/output/static --project-name=MY_PROJECT_NAME\n```\n\n# App Code\nI used files made by `npx @sentry/wizard@latest -i nextjs` to test.\n\n## app/api/sentry-example-api/route.ts\n```typescript\nimport { NextResponse } from 'next/server';\n\nexport const dynamic = 'force-dynamic';\nexport const runtime = 'edge';\n\n// A faulty API route to test Sentry's error monitoring\nexport function GET() {\n throw new Error('Sentry Example API Route Error');\n return NextResponse.json({ data: 'Testing Sentry Error...' });\n}\n```\n\n## app/sentry-example-page/page.tsx\n```tsx\n'use client';\n\nimport * as Sentry from '@sentry/nextjs';\nimport Head from 'next/head';\n\nexport default function Page() {\n return (\n \u003cdiv>\n \u003cHead>\n \u003ctitle>Sentry Onboarding\u003c/title>\n \u003cmeta name=\"description\" content=\"Test Sentry for your Next.js app!\" />\n \u003c/Head>\n\n \u003cmain\n style={{\n minHeight: '100vh',\n display: 'flex',\n flexDirection: 'column',\n justifyContent: 'center',\n alignItems: 'center',\n }}\n >\n \u003ch1 style={{ fontSize: '4rem', margin: '14px 0' }}>\n \u003csvg\n style={{\n height: '1em',\n }}\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 200 44\"\n >\n \u003cpath\n fill=\"currentColor\"\n d=\"M124.32,28.28,109.56,9.22h-3.68V34.77h3.73V15.19l15.18,19.58h3.26V9.22h-3.73ZM87.15,23.54h13.23V20.22H87.14V12.53h14.93V9.21H83.34V34.77h18.92V31.45H87.14ZM71.59,20.3h0C66.44,19.06,65,18.08,65,15.7c0-2.14,1.89-3.59,4.71-3.59a12.06,12.06,0,0,1,7.07,2.55l2-2.83a14.1,14.1,0,0,0-9-3c-5.06,0-8.59,3-8.59,7.27,0,4.6,3,6.19,8.46,7.52C74.51,24.74,76,25.78,76,28.11s-2,3.77-5.09,3.77a12.34,12.34,0,0,1-8.3-3.26l-2.25,2.69a15.94,15.94,0,0,0,10.42,3.85c5.48,0,9-2.95,9-7.51C79.75,23.79,77.47,21.72,71.59,20.3ZM195.7,9.22l-7.69,12-7.64-12h-4.46L186,24.67V34.78h3.84V24.55L200,9.22Zm-64.63,3.46h8.37v22.1h3.84V12.68h8.37V9.22H131.08ZM169.41,24.8c3.86-1.07,6-3.77,6-7.63,0-4.91-3.59-8-9.38-8H154.67V34.76h3.8V25.58h6.45l6.48,9.2h4.44l-7-9.82Zm-10.95-2.5V12.6h7.17c3.74,0,5.88,1.77,5.88,4.84s-2.29,4.86-5.84,4.86Z M29,2.26a4.67,4.67,0,0,0-8,0L14.42,13.53A32.21,32.21,0,0,1,32.17,40.19H27.55A27.68,27.68,0,0,0,12.09,17.47L6,28a15.92,15.92,0,0,1,9.23,12.17H4.62A.76.76,0,0,1,4,39.06l2.94-5a10.74,10.74,0,0,0-3.36-1.9l-2.91,5a4.54,4.54,0,0,0,1.69,6.24A4.66,4.66,0,0,0,4.62,44H19.15a19.4,19.4,0,0,0-8-17.31l2.31-4A23.87,23.87,0,0,1,23.76,44H36.07a35.88,35.88,0,0,0-16.41-31.8l4.67-8a.77.77,0,0,1,1.05-.27c.53.29,20.29,34.77,20.66,35.17a.76.76,0,0,1-.68,1.13H40.6q.09,1.91,0,3.81h4.78A4.59,4.59,0,0,0,50,39.43a4.49,4.49,0,0,0-.62-2.28Z\"\n >\u003c/path>\n \u003c/svg>\n \u003c/h1>\n\n \u003cp>Get started by sending us a sample error:\u003c/p>\n \u003cbutton\n type=\"button\"\n style={{\n padding: '12px',\n cursor: 'pointer',\n backgroundColor: '#AD6CAA',\n borderRadius: '4px',\n border: 'none',\n color: 'white',\n fontSize: '14px',\n margin: '18px',\n }}\n onClick={async () => {\n await Sentry.startSpan(\n {\n name: 'Example Frontend Span',\n op: 'test',\n },\n async () => {\n const res = await fetch('/api/sentry-example-api');\n if (!res.ok) {\n throw new Error('Sentry Example Frontend Error');\n }\n }\n );\n }}\n >\n Throw error!\n \u003c/button>\n\n \u003cp>\n Next, look for the error on the{' '}\n \u003ca href=\"https://heyinc.sentry.io/issues/?project=4506675767803904\">\n Issues Page\n \u003c/a>\n .\n \u003c/p>\n \u003cp style={{ marginTop: '24px' }}>\n For more information, see{' '}\n \u003ca href=\"https://docs.sentry.io/platforms/javascript/guides/nextjs/\">\n https://docs.sentry.io/platforms/javascript/guides/nextjs/\n \u003c/a>\n \u003c/p>\n \u003c/main>\n \u003c/div>\n );\n}\n```\n\n### Steps to Reproduce\n\nI am trying to migrate v8 from v7 in my project with next@14.2.4 and deploy to Cloudflare Pages.\nIt used to work all fine while using v7 SDK, but after migrating v8, it stops flushing error caused in route handler.\nAnd it's only in the Cloudflare Pages Edge runtime, local dev server works fine. Also client errors captured in both local and Cloudflare Pages.\n\nHere's a migrating steps I have tried;\n\n1. Steps up 7.120.2 before migrating v8\n2. Enabled `instrumentationHook` in next.config.mjs\n3. Made instrumentation.ts that loads different config files by each nodejs/edge runtime. It worked all OK at this time.\n4. `npx @sentry/migr8` and installed SDK 8.47.0\n5. build by `npx @cloudflare/next-on-pages` failed\n6. downgrade SDK v8.35.0 build successfully. (ref: https://github.com/cloudflare/next-on-pages/issues/678) but it did not flush events in Edge runtime routes (/api/sentry-example-api).\n7. upgrade SDK v8.47.0 and build with `npx @cloudflare/next-on-pages --disableChunksDedup` . Build successfully, though the bundle size is super high, still doesn't flush events in Edge runtime.\n\nI am doubting the compatibility with Cloudflare Pages and the SDK.\n\n\n### Expected Result\n\nFlushes errors in Cloudflare Pages Edge runtime, like route handlers.\n\n### Actual Result\n\nOnly client errors are captured in the Cloudflare Pages.","author":{"url":"https://github.com/tttttahiti","@type":"Person","name":"tttttahiti"},"datePublished":"2025-01-08T02:57:19Z","url":"https://github.com/getsentry/sentry-javascript/issues/14931"}
| 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:5de079f1-3f4b-1d4c-dfde-13d9fba8d3dc |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C03A:35E323:9E0754:DDB375:6B042FE3 |
| html-safe-nonce | d3a306bc1a2ef6c72ac5b885010aac0f9f48931329fe5d551119a37acee2b2e0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMDNBOjM1RTMyMzo5RTA3NTQ6RERCMzc1OjZCMDQyRkUzIiwidmlzaXRvcl9pZCI6IjE1ODc2NDMyOTU2NDYxMDE0NzUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 83f1ecff6f254d2c4600fd85903df3c78ff6845db405cd525332463c0529b2bd |
| hovercard-subject-tag | issue:2774128120 |
| 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/14931/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7c8b7927c48691ced1e13091332a849866d2372d2fcb7ab9d1db8b4da484f859/getsentry/sentry-javascript/issues/14931 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7c8b7927c48691ced1e13091332a849866d2372d2fcb7ab9d1db8b4da484f859/getsentry/sentry-javascript/issues/14931 |
| 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 | tttttahiti |
| hostname | github.com |
| expected-hostname | github.com |
| None | b7a1d2b9101496921b08579fbee988d014345aef2f5bd660d1f8c7332d81560e |
| 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 | c3dd496c3da6ea6b77e69c09279d2b81604654f1 |
| 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