Title: wrapGetInitialPropsWithSentry throws an exception if getInitialProps returns undefined · Issue #9066 · getsentry/sentry-javascript · GitHub
Open Graph Title: wrapGetInitialPropsWithSentry throws an exception if getInitialProps returns undefined · Issue #9066 · getsentry/sentry-javascript
X Title: wrapGetInitialPropsWithSentry throws an exception if getInitialProps returns undefined · Issue #9066 · 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/9066
X: @github
Domain: github.com
IPv4 address: 140.82.113.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"wrapGetInitialPropsWithSentry throws an exception if getInitialProps returns undefined","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\n7.69.0\n\n### Framework Version\n\nReact 17.0, NextJS 12.1.0\n\n### Link to Sentry event\n\nhttps://ardian.sentry.io/issues/4480381245/\n\n### SDK Setup\n\n_No response_\n\n### Steps to Reproduce\n\nIf a page's `getInitialProps` function does not return an object, but rather undefined or null, Sentry will throw an exception on that page. This is because of this piece of code in `wrapGetInitialPropsWithSentry.ts` :\r\n\r\n```\r\nconst initialProps: {\r\n _sentryTraceData?: string;\r\n _sentryBaggage?: string;\r\n } = await tracedGetInitialProps.apply(thisArg, args);\r\n\r\n const requestTransaction = getTransactionFromRequest(req) ?? hub.getScope().getTransaction();\r\n if (requestTransaction) {\r\n initialProps._sentryTraceData = requestTransaction.toTraceparent();\r\n\r\n const dynamicSamplingContext = requestTransaction.getDynamicSamplingContext();\r\n initialProps._sentryBaggage = dynamicSamplingContextToSentryBaggageHeader(dynamicSamplingContext);\r\n }\r\n\r\n return initialProps;\r\n```\r\n\r\nThe specific error is `TypeError: Cannot set properties of undefined (setting '_sentryTraceData')`\r\n\r\nFor context, I had a page's `getInitialProps` returning undefined because I only used `getInitialProps` to handle server-side redirections.\r\n\r\nI don't know if this can easliy modified whilde still keeping the instrumentation, but the exception could at least be caught to not bubble up and crash the whole page.\n\n### Expected Result\n\nSentry doesn't throw an exception if `getInitialProps` returns undefined\n\n### Actual Result\n\nSentry throws an exception if `getInitialProps` returns undefined, crashing the whole page.","author":{"url":"https://github.com/Eszik","@type":"Person","name":"Eszik"},"datePublished":"2023-09-20T08:41:13Z","url":"https://github.com/getsentry/sentry-javascript/issues/9066"}
| 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:dac2af6e-47c0-7b89-e6c2-52c29f78e067 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8798:2B7161:1A0A07:22A9CA:6B04CC7E |
| html-safe-nonce | 8844589ad02fe5cf6c05fc2d37a3c4e0f37eb0860a58d35d59c8e2ec03be2215 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4Nzk4OjJCNzE2MToxQTBBMDc6MjJBOUNBOjZCMDRDQzdFIiwidmlzaXRvcl9pZCI6IjQwMDc4MzMwMjA0MzEwNjU1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 812ab9561d090fce842bee2a371a0c84ec20a9abbd90398f9d7e756f3291f91d |
| hovercard-subject-tag | issue:1904484655 |
| 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/9066/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d1b1f44f29f01b4393b0ce869c3101c532155993839a91dbe2ca179137b66899/getsentry/sentry-javascript/issues/9066 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d1b1f44f29f01b4393b0ce869c3101c532155993839a91dbe2ca179137b66899/getsentry/sentry-javascript/issues/9066 |
| 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 | Eszik |
| hostname | github.com |
| expected-hostname | github.com |
| None | 27ed421e5c2dac040a37529b5b9191edcc4a3de70521471e81fb4b4d9dc2aa7d |
| 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 | 63dc19014c621c67306d7899c04c78dcd0d95803 |
| 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