Title: NextJS SSG Error Handling Not Working, Client-side does · Issue #6255 · getsentry/sentry-javascript · GitHub
Open Graph Title: NextJS SSG Error Handling Not Working, Client-side does · Issue #6255 · getsentry/sentry-javascript
X Title: NextJS SSG Error Handling Not Working, Client-side does · Issue #6255 · getsentry/sentry-javascript
Description: Discussed in #6254 Originally posted by chris-erickson November 21, 2022 I'm struggling a lot to understand why the server-side error handling isn't working. We have had client side working for quite some time, I'm not sure if server sid...
Open Graph Description: Discussed in #6254 Originally posted by chris-erickson November 21, 2022 I'm struggling a lot to understand why the server-side error handling isn't working. We have had client side working for qui...
X Description: Discussed in #6254 Originally posted by chris-erickson November 21, 2022 I'm struggling a lot to understand why the server-side error handling isn't working. We have had client side working...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/6255
X: @github
Domain: github.com
IPv4 address: 140.82.113.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"NextJS SSG Error Handling Not Working, Client-side does","articleBody":"### Discussed in https://github.com/getsentry/sentry-javascript/discussions/6254\r\n\r\n\u003cdiv type='discussions-op-text'>\r\n\r\n\u003csup>Originally posted by **chris-erickson** November 21, 2022\u003c/sup>\r\nI'm struggling a lot to understand why the _server-side_ error handling isn't working. We have had client side working for quite some time, I'm not sure if server side has ever worked for us (so, I can't point specifically to something we maybe changed as a clue).\r\n\r\nVersions:\r\n```\r\n\"next\": \"13.0.4\",\r\n\"@sentry/nextjs\": \"7.20.0\",\r\n```\r\n\r\nI made a testing page that will throw either in `getServerSideProps` directly, or in an async function called there (to simulate a third-party API call that dies for some reason). When I load the page in Vercel, the logs emit:\r\n\r\n```\r\nSentry Logger [log]: Initializing SDK...\r\nSentry Logger [log]: Integration installed: InboundFilters\r\nSentry Logger [log]: Integration installed: FunctionToString\r\nSentry Logger [log]: Integration installed: Console\r\nSentry Logger [log]: Integration installed: Http\r\nSentry Logger [log]: Integration installed: OnUncaughtException\r\nSentry Logger [log]: Integration installed: OnUnhandledRejection\r\nSentry Logger [log]: Integration installed: ContextLines\r\nSentry Logger [log]: Integration installed: Context\r\nSentry Logger [log]: Integration installed: Modules\r\nSentry Logger [log]: Integration installed: RequestData\r\nSentry Logger [log]: Integration installed: LinkedErrors\r\nSentry Logger [log]: Integration installed: RewriteFrames\r\nSentry Logger [log]: SDK successfully initialized\r\nSentry Logger [log]: [Tracing] starting http.server transaction - /errorTester\r\nSentry Logger [log]: [Tracing] Starting 'function.nextjs' span on transaction '/errorTester' (8e631fbcf4828329).\r\nSentry Logger [log]: [Tracing] Finishing 'function.nextjs' span on transaction '/errorTester' (8e631fbcf4828329).\r\n2022-11-21T17:02:12.769Z\t041218a1-9b0d-4a17-ae99-7c9a27170c39\tERROR\tError: This happened inside the API\r\n at tester (/var/task/packages/site/.next/server/pages/errorTester.js:51:11)\r\n at getServerSideProps (/var/task/packages/site/.next/server/pages/errorTester.js:71:15)\r\n at /var/task/node_modules/@sentry/nextjs/cjs/config/wrappers/wrapperUtils.js:34:33\r\n at /var/task/node_modules/@sentry/nextjs/cjs/config/wrappers/wrapperUtils.js:113:20\r\n at bound (node:domain:421:15)\r\n at runBound (node:domain:432:12)\r\n at Object.callTracedServerSideDataFetcher (/var/task/node_modules/@sentry/nextjs/cjs/config/wrappers/wrapperUtils.js:128:5)\r\n at /var/task/node_modules/@sentry/nextjs/cjs/config/wrappers/withSentryGetServerSideProps.js:32:50\r\n at Object.renderToHTML (/var/task/node_modules/next/dist/server/render.js:506:26)\r\n at processTicksAndRejections (node:internal/process/task_queues:96:5) {\r\n page: '/errorTester'\r\n}\r\nRequestId: 041218a1-9b0d-4a17-ae99-7c9a27170c39 Error: Runtime exited with error: exit status 1\r\nRuntime.ExitError\r\n```\r\nwhen I run it locally with `build/serve` I get: \r\n```\r\nready - started server on 0.0.0.0:3000, url: http://localhost:3000\r\ninfo - Loaded env from /Users/me/Development/ginrickey/packages/site/.env.local\r\ninfo - Loaded env from /Users/me/Development/ginrickey/packages/site/.env.production\r\nSentry Logger [log]: Initializing SDK...\r\nSentry Logger [log]: Integration installed: InboundFilters\r\nSentry Logger [log]: Integration installed: FunctionToString\r\nSentry Logger [log]: Integration installed: Console\r\nSentry Logger [log]: Integration installed: Http\r\nSentry Logger [log]: Integration installed: OnUncaughtException\r\nSentry Logger [log]: Integration installed: OnUnhandledRejection\r\nSentry Logger [log]: Integration installed: ContextLines\r\nSentry Logger [log]: Integration installed: Context\r\nSentry Logger [log]: Integration installed: Modules\r\nSentry Logger [log]: Integration installed: RequestData\r\nSentry Logger [log]: Integration installed: LinkedErrors\r\nSentry Logger [log]: Integration installed: RewriteFrames\r\nSentry Logger [log]: SDK successfully initialized\r\nSentry Logger [log]: [Tracing] starting http.server transaction - /errorTester\r\nSentry Logger [log]: [Tracing] starting http.server transaction - /errorTester\r\nSentry Logger [log]: [Tracing] Starting 'function.nextjs' span on transaction '/errorTester' (848e345adae7a90f).\r\nSentry Logger [log]: [Tracing] Finishing 'function.nextjs' span on transaction '/errorTester' (848e345adae7a90f).\r\nSentry Logger [log]: Not capturing exception because it's already been captured.\r\nError: This happened inside the API\r\n at tester (/Users/me/Development/ginrickey/packages/site/.next/server/pages/errorTester.js:51:11)\r\n at getServerSideProps (/Users/me/Development/ginrickey/packages/site/.next/server/pages/errorTester.js:71:15)\r\n at /Users/me/Development/ginrickey/node_modules/@sentry/nextjs/cjs/config/wrappers/wrapperUtils.js:34:33\r\n at /Users/me/Development/ginrickey/node_modules/@sentry/nextjs/cjs/config/wrappers/wrapperUtils.js:113:20\r\n at bound (node:domain:421:15)\r\n at runBound (node:domain:432:12)\r\n at Object.callTracedServerSideDataFetcher (/Users/me/Development/ginrickey/node_modules/@sentry/nextjs/cjs/config/wrappers/wrapperUtils.js:128:5)\r\n at /Users/me/Development/ginrickey/node_modules/@sentry/nextjs/cjs/config/wrappers/withSentryGetServerSideProps.js:32:50\r\n at Object.renderToHTML (/Users/me/Development/ginrickey/node_modules/next/dist/server/render.js:506:26)\r\n at runMicrotasks (\u003canonymous>)\r\nSentry Logger [log]: [Tracing] Starting 'function.nextjs' span on transaction '/errorTester' (848e345adae7a90f).\r\nSentry Logger [log]: Not capturing exception because it's already been captured.\r\nSentry: should send\r\nSentry: should send\r\nSentry Logger [log]: [Tracing] Finishing 'function.nextjs' span on transaction '/errorTester' (848e345adae7a90f).\r\nSentry Logger [log]: [Tracing] Starting 'function.nextjs' span on transaction '/errorTester' (848e345adae7a90f).\r\nSentry Logger [log]: [Tracing] Finishing 'function.nextjs' span on transaction '/errorTester' (848e345adae7a90f).\r\nSentry Logger [log]: [Tracing] Finishing http.server transaction: /errorTester.\r\nSentry Logger [log]: Flushing events...\r\nSentry Logger [log]: Done flushing events\r\nSentry Logger [log]: [Tracing] Finishing http.server transaction: /500.\r\n```\r\nnote that\r\n```\r\nSentry: should send\r\nSentry: should send\r\n```\r\ncomes from the `sentry.server.config.js` and it's only present in the local use case. This leads me to believe _something_ is disabling sentry when it's deployed but I don't for the life of me know what could be doing that or how to examine it.\r\n```javascript\r\nimport * as Sentry from '@sentry/nextjs';\r\n\r\nconst SENTRY_DSN = process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN;\r\n\r\nSentry.init({\r\n dsn: SENTRY_DSN,\r\n environment: process.env.ACTIVE_ENV,\r\n tracesSampleRate: 1.0,\r\n debug: true,\r\n beforeSend: (e) => {\r\n console.log('Sentry: should send');\r\n return e;\r\n },\r\n});\r\n```\r\nRelevant parts of the next config looks like \r\n```javascript\r\nconst { formatInTimeZone } = require('date-fns-tz');\r\nconst { withSentryConfig } = require('@sentry/nextjs');\r\n\r\nconst ENVIRONMENTS = {\r\n DEV: 'dev',\r\n STAGE: 'staging',\r\n PROD: 'production',\r\n};\r\nconst nextjsEnvironment = process.env.ACTIVE_ENV;\r\nlet ENVIRONMENT;\r\nif (nextjsEnvironment === ENVIRONMENTS.STAGE) {\r\n ENVIRONMENT = ENVIRONMENTS.STAGE;\r\n} else if (nextjsEnvironment === ENVIRONMENTS.PROD) {\r\n ENVIRONMENT = ENVIRONMENTS.PROD;\r\n} else {\r\n ENVIRONMENT = ENVIRONMENTS.DEV;\r\n}\r\n\r\nconst isDev =\r\n nextjsEnvironment !== ENVIRONMENTS.STAGE &&\r\n nextjsEnvironment !== ENVIRONMENTS.PROD;\r\nconst isProd = nextjsEnvironment === ENVIRONMENTS.PROD;\r\n\r\nconst SITE_URL =\r\n process.env.SITE_URL ||\r\n process.env.URL ||\r\n process.env.DEPLOY_URL ||\r\n 'https://oursite';\r\n\r\nconst BRANCH =\r\n process.env.VERCEL_GIT_COMMIT_REF || process.env.BRANCH || 'unset';\r\nconst possibleCommitRef =\r\n process.env.VERCEL_GIT_COMMIT_SHA || process.env.COMMIT_REF || '000000';\r\nconst COMMIT_REF = possibleCommitRef.slice(0, 6);\r\n\r\nconst now = new Date();\r\nconst BUILD_DATETIME_HUMAN = formatInTimeZone(\r\n now,\r\n 'America/Chicago',\r\n `EEE. MMMM d, yyyy, K:mm aa 'Central'`\r\n);\r\n\r\nconst SentryWebpackPluginOptions = {\r\n silent: false,\r\n debug: true,\r\n};\r\n\r\n/**\r\n * @type {import('next').NextConfig}\r\n */\r\nconst nextConfig = {\r\n swcMinify: true,\r\n reactStrictMode: true,\r\n trailingSlash: false,\r\n productionBrowserSourceMaps: true,\r\n images: {\r\n domains: ['cdn.sanity.io'],\r\n // disableStaticImages: true,\r\n },\r\n // These vars are injected at build time, and are accessible as `process.env.KEY` in site code\r\n env: {\r\n BRANCH: BRANCH,\r\n COMMIT_REF: COMMIT_REF,\r\n BUILD_DATETIME_HUMAN: BUILD_DATETIME_HUMAN,\r\n ACTIVE_ENV: ENVIRONMENT,\r\n SITE_URL: SITE_URL,\r\n SANITY_PROJECT_ID: process.env.SANITY_PROJECT_ID,\r\n SANITY_DATASET: process.env.SANITY_DATASET,\r\n SANITY_READ_TOKEN: process.env.SANITY_READ_TOKEN || '',\r\n THEMIS_URL: process.env.THEMIS_URL || 'https://example.com/graphql',\r\n GIT_REF: process.env.COMMIT_REF,\r\n SENTRY_DSN: process.env.SENTRY_DSN,\r\n FATHOM_SITE_ID: process.env.FATHOM_SITE_ID,\r\n MAPBOX_TOKEN: process.env.MAPBOX_TOKEN,\r\n ENVIRONMENTS: ENVIRONMENTS,\r\n IS_PROD: isProd,\r\n },\r\n eslint: {\r\n // We check in CI, so this is duplicate effort: https://nextjs.org/docs/api-reference/next.config.js/ignoring-eslint\r\n ignoreDuringBuilds: true,\r\n },\r\n webpack: (config, options) => {\r\n config.module.rules.push({\r\n test: /\\.svg$/,\r\n use: [\r\n options.defaultLoaders.babel,\r\n {\r\n loader: '@svgr/webpack',\r\n options: { babel: false },\r\n },\r\n ],\r\n });\r\n return config;\r\n },\r\n};\r\n\r\nmodule.exports = withSentryConfig(nextConfig, SentryWebpackPluginOptions);\r\n\r\n```\u003c/div>","author":{"url":"https://github.com/AbhiPrasad","@type":"Person","name":"AbhiPrasad"},"datePublished":"2022-11-21T18:57:55Z","url":"https://github.com/getsentry/sentry-javascript/issues/6255"}
| 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:91012e9a-e155-5340-cac2-d8b3f0e06724 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D3CE:35E323:A1D7FC:E30F64:6B04311D |
| html-safe-nonce | 5ea82a39f0ea09210bd600df22bb9c0c148621749a9326c103912dc2583083e6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEM0NFOjM1RTMyMzpBMUQ3RkM6RTMwRjY0OjZCMDQzMTFEIiwidmlzaXRvcl9pZCI6IjQzODI2MzgwMjEzNzIyOTM0MDUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 9061bb667bbff0a15f3688624254d7d9dd8328a9c2cb71b61652c48f6f22f19e |
| hovercard-subject-tag | issue:1458429571 |
| 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/6255/issue_layout |
| twitter:image | https://opengraph.githubassets.com/87d24622f6e4d2cdc3f40184b04e4393ecb0301753a2b4ebdd81f10bfcb64381/getsentry/sentry-javascript/issues/6255 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/87d24622f6e4d2cdc3f40184b04e4393ecb0301753a2b4ebdd81f10bfcb64381/getsentry/sentry-javascript/issues/6255 |
| og:image:alt | Discussed in #6254 Originally posted by chris-erickson November 21, 2022 I'm struggling a lot to understand why the server-side error handling isn't working. We have had client side working for qui... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | AbhiPrasad |
| 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