Title: Improve Nextjs tracing · Issue #5505 · getsentry/sentry-javascript · GitHub
Open Graph Title: Improve Nextjs tracing · Issue #5505 · getsentry/sentry-javascript
X Title: Improve Nextjs tracing · Issue #5505 · getsentry/sentry-javascript
Description: Goal: Improve tracing in nextjs SDK - make parameterization more reliable, trace data fetchers, trace page requests for folks on Vercel TL;DR Plan: get page path at build time use loader to inject into page as global variable use loader ...
Open Graph Description: Goal: Improve tracing in nextjs SDK - make parameterization more reliable, trace data fetchers, trace page requests for folks on Vercel TL;DR Plan: get page path at build time use loader to inject ...
X Description: Goal: Improve tracing in nextjs SDK - make parameterization more reliable, trace data fetchers, trace page requests for folks on Vercel TL;DR Plan: get page path at build time use loader to inject ...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/5505
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Improve Nextjs tracing","articleBody":"Goal: Improve tracing in nextjs SDK - make parameterization more reliable, trace data fetchers, trace page requests for folks on Vercel\r\n\r\nTL;DR Plan:\r\n- get page path at build time\r\n- use loader to inject into page as global variable\r\n- use loader to wrap canonical functions\r\n - getStaticPaths - start transaction, add span\r\n - getStaticProps - start or continue transaction, add span\r\n - getServerSideProps - start transaction, add span\r\n - getInitialProps - needs investigation, can run on client\r\n- use loader to wrap _app or _document\r\n - start or continue transaction, add span, finish transaction\r\n\r\nEffects:\r\n- Parameterized name is known when transaction is started\r\n- Wrapping is at page level, not server level, so works on and off of Vercel (currently tracing for page requests only works off of Vercel)\r\n- Spans for data-fetching functions (none now)\r\n- Hopefully lets us eventually retire `instrumentServer` (brittle monkeypatching, only works off of vercel)\r\n\r\nOpen Questions:\r\n- How to deal with domains when action happens in multiple functions at multiple times?\r\n- What about background/pre-load/data-only requests?\r\n- How to communicate why transactions may get marginally shorter?\r\n- How to grab request data if no GSSP?\r\n\r\n---\r\n\r\n## Tasks\r\n\r\n⚠️ ... Required for making changes non-experimental\r\n\r\n### Prework\r\n\r\nGeneral prework necessary to improve the Next.js performance experience as a whole.\r\n\r\n- [x] ⚠️ Add loader to inject prefix for `RewriteFrames` (https://github.com/getsentry/sentry-javascript/pull/5445)\r\n- [x] ⚠️ Create MVP for experimental loader to wrap `getServerSideProps`, `getStaticProps` and `getStaticPaths` during build-time (https://github.com/getsentry/sentry-javascript/pull/5503)\r\n- [x] ⚠️ Actually, don't wrap `getStaticPaths` (https://github.com/getsentry/sentry-javascript/pull/5561)\r\n- [x] ⚠️ Turn loader MVP into sustainable solution (https://github.com/getsentry/sentry-javascript/pull/5602)\r\n\r\n### Transaction Name Parameterization\r\n\r\n- [x] ⚠️ Have spans and proper transaction names for `getServerSideProps` and `getStaticProps` (https://github.com/getsentry/sentry-javascript/pull/5564)\r\n- [x] ⚠️ Have spans and proper transaction names for `getInitialProps` for normal pages (not `_app.js`, `_error.js`, `_document.js`) (https://github.com/getsentry/sentry-javascript/pull/5587)\r\n- [x] ⚠️ Have spans and proper transaction names for `getInitialProps` in `_app.js`, `_error.js` and `_document.js` (https://github.com/getsentry/sentry-javascript/pull/5604)\r\n\r\n### Connected Traces\r\n\r\n- [x] ⚠️ Allow for connected traces when traces start on Next.js server (frontend changes) (https://github.com/getsentry/sentry-javascript/pull/5574)\r\n- [x] ⚠️ Extract traceparent data from incoming requests in data functions and attach it to transactions and send trace parent data and baggage from data fetching methods (Make sure to handle `redirect` and `notFound` responses from `getServerSideProps` (also `getStaticProps`?)) (https://github.com/getsentry/sentry-javascript/pull/5655)\r\n- [x] ⚠️ Find a solution for data fetchers + navigation transactions (https://github.com/getsentry/sentry-javascript/pull/5676)\r\n- [ ] Somehow mark prefetch requests (add `isPrefetchRequest: boolean` tag to errors and do the one or more of the following to transactions 1. different name 2. data field 3. different op) (there is a `purpose: prefetch` header in those requests)\r\n- [ ] Solve the case when navigating to a `getServerSideProps` page that throws: Transaction name is `/_error` but DSC contains route of `getServerSideProps`. (See `TODO` comment in src/performance/client.ts) (https://github.com/getsentry/sentry-javascript/issues/5826)\r\n\r\n### Serverside Transaction improvements\r\n\r\nCurrently, for mysterious reasons, in some circumstances no server-side non-API-route transactions are started for Next.js apps. (This is over and above the known limitation of non-API-route tracing not working on Vercel.) The following changes will enable serverside transactions in both those mysterious situations and on Vercel.\r\n\r\n- [x] ⚠️ Have serverside transactions by starting transactions inside `getInitialProps` and `getServerSideProps` (https://github.com/getsentry/sentry-javascript/pull/5593)\r\n- [x] ⚠️ Add request data to transactions started by data-fetching functions (https://github.com/getsentry/sentry-javascript/pull/5703)\r\n- [x] ⚠️ Extend `RequestData` integration to work for error events (https://github.com/getsentry/sentry-javascript/pull/5729)\r\n- [ ] Automatically wrap `getStaticProps` (Wrapper exists but we don't have access to the request. Is this solvable? Do we even care, given that this generally runs in the background?)\r\n- [ ] Add proper error monitoring in data fetchers (by extracting logic from `withSentry` into a wrapper/helper)\r\n- [x] ⚠️ Figure out how to block `res.send` similar to how we do it in `withSentry` (https://github.com/getsentry/sentry-javascript/pull/5814)\r\n- [ ] ~Figure out how to propagate scope between data-fetching functions in the same transaction (or~ document scope-propagation limitations)\r\n- [ ] Delete `instrumentServer.ts`?\r\n- [x] ⚠️ Add \"ok\" `status` to transactions and spans and update to \"internal_error\" on error (https://github.com/getsentry/sentry-javascript/pull/5777)\r\n- [ ] ~What happens for pages with no data fetchers? Should `_app` have a different helper? (no name for transaction)~\r\n- [x] ⚠️ Automatically wrap API routes (https://github.com/getsentry/sentry-javascript/pull/5778)\r\n\r\n### Folow-up/Cleanup/Polishing\r\n\r\n- [x] ⚠️ Remove MVP loader code and remove its dependencies from `package.json` (https://github.com/getsentry/sentry-javascript/pull/5713)\r\n- [ ] Use `RequestData` integration everywhere\r\n- [ ] ~Check if new model works with CJS, if no, support people that use CJS~\r\n- [x] ⚠️ Check Webpack 4 support of the loaders we created (our integration tests run under webpack 4 just fine, so I think we're good here)\r\n- [ ] Bring `withSentry` into the fold (consolidate helpers)\r\n- [x] Nudge users to stop wrapping API routes if using auto-wrapping (once auto-wrapping includes API routes)\r\n- [ ] Factor more common parts out of wrappers if possible\r\n\r\n### Documentation\r\n- [ ] Document new `RequestData` integration and options\r\n- [x] Document auto-wrapping\r\n\r\n### Misc (stretch goals)\r\n\r\n- [ ] Have spans for `getInitialProps` when run client-side\r\n- [ ] Add instrumentation for how long server-side rendering takes\r\n- [ ] Investigate how it would be possible to support [custom servers](https://nextjs.org/docs/advanced-features/custom-server)\r\n- [ ] Can common route-handling work be consolidated into helper functions across frameworks, so we're not always reinventing the wheel?\r\n\r\n### Steps for Beta\r\n\r\n- [x] Rename option and make it an actual option (https://github.com/getsentry/sentry-javascript/pull/5793)\r\n- [x] Add option to wizard (https://github.com/getsentry/sentry-wizard/pull/194, https://github.com/getsentry/sentry-wizard/pull/195)\r\n- [x] Update docs that explains auto wrapping and new option (https://github.com/getsentry/sentry-docs/pull/5542) \r\n- [ ] Update Next.js examples (https://github.com/vercel/next.js/pull/41326)\r\n\r\n### Steps for GA (Planned date: October 5, 2022)\r\n\r\n- [x] Remove option from wizard (https://github.com/getsentry/sentry-wizard/pull/196)\r\n- [x] Flip default for option (https://github.com/getsentry/sentry-javascript/pull/5919)\r\n- [x] Update docs - removing the section where we tell people to wrap routes with `withSentry` (https://github.com/getsentry/sentry-docs/pull/5543)\r\n\r\n---------------------------------\r\n\r\n### Follow ups\r\n\r\nUndone tasks from above have been sorted into:\r\n\r\n- Clean up/consolidation of wrapper code (in nextjs, and across packages: https://github.com/getsentry/sentry-javascript/issues/5599)\r\n- Expanded coverage of less-common/not-yet-handled cases (https://github.com/getsentry/sentry-javascript/issues/5827)\r\n- v8 deprecations - `withSentry` and possibly `instrumentServer` (https://github.com/getsentry/sentry-javascript/issues/5194)\r\n- Handling `_error` better (https://github.com/getsentry/sentry-javascript/issues/5826)\r\n- Further work on `RequestData` integration (https://github.com/getsentry/sentry-javascript/issues/5756)","author":{"url":"https://github.com/smeubank","@type":"Person","name":"smeubank"},"datePublished":"2022-08-01T14:09:12Z","url":"https://github.com/getsentry/sentry-javascript/issues/5505"}
| 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:02c528bc-ab2d-486a-02d4-ff0a75960c19 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B610:21DE8C:05BE:074E:6B0426F3 |
| html-safe-nonce | aa814513e035344c4c5ddfde8d07cf866afa210b333f63d540221101b7d74fd3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNjEwOjIxREU4QzowNUJFOjA3NEU6NkIwNDI2RjMiLCJ2aXNpdG9yX2lkIjoiMzUzNDY1MDM2ODYyMzY1MDU0NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | abaefec291d4faa7aa55a29e8c39105c918c142b2909b34ff5557aff464ab7ed |
| hovercard-subject-tag | issue:1324490391 |
| 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/5505/issue_layout |
| twitter:image | https://opengraph.githubassets.com/cc5ef4bfea2be4d98ce68d673ef8d93bf99b6765f2c4ecfc8f4c2c474a0032c9/getsentry/sentry-javascript/issues/5505 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/cc5ef4bfea2be4d98ce68d673ef8d93bf99b6765f2c4ecfc8f4c2c474a0032c9/getsentry/sentry-javascript/issues/5505 |
| og:image:alt | Goal: Improve tracing in nextjs SDK - make parameterization more reliable, trace data fetchers, trace page requests for folks on Vercel TL;DR Plan: get page path at build time use loader to inject ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | smeubank |
| 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