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 to wrap canonical functions
- getStaticPaths - start transaction, add span
- getStaticProps - start or continue transaction, add span
- getServerSideProps - start transaction, add span
- getInitialProps - needs investigation, can run on client
- use loader to wrap _app or _document
- start or continue transaction, add span, finish transaction
Effects:
- Parameterized name is known when transaction is started
- 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)
- Spans for data-fetching functions (none now)
- Hopefully lets us eventually retire
instrumentServer (brittle monkeypatching, only works off of vercel)
Open Questions:
- How to deal with domains when action happens in multiple functions at multiple times?
- What about background/pre-load/data-only requests?
- How to communicate why transactions may get marginally shorter?
- How to grab request data if no GSSP?
Tasks
⚠️ ... Required for making changes non-experimental
Prework
General prework necessary to improve the Next.js performance experience as a whole.
Transaction Name Parameterization
Connected Traces
Serverside Transaction improvements
Currently, 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.
Folow-up/Cleanup/Polishing
Documentation
Misc (stretch goals)
Steps for Beta
Steps for GA (Planned date: October 5, 2022)
Follow ups
Undone tasks from above have been sorted into:
Goal: Improve tracing in nextjs SDK - make parameterization more reliable, trace data fetchers, trace page requests for folks on Vercel
TL;DR Plan:
Effects:
instrumentServer(brittle monkeypatching, only works off of vercel)Open Questions:
Tasks
Prework
General prework necessary to improve the Next.js performance experience as a whole.
RewriteFrames(ref(nextjs): Use loader to setRewriteFrameshelper value #5445)getServerSideProps,getStaticPropsandgetStaticPathsduring build-time (ref(nextjs): Wrap server-side data-fetching methods during build #5503)getStaticPaths(fix(nextjs): Remove experimental wrapping ofgetStaticPaths#5561)Transaction Name Parameterization
getServerSidePropsandgetStaticProps(feat(nextjs): Add spans and route parameterization in data fetching wrappers #5564)getInitialPropsfor normal pages (not_app.js,_error.js,_document.js) (feat(nextjs): Create spans and route parameterization in server-sidegetInitialProps#5587)getInitialPropsin_app.js,_error.jsand_document.js(feat(nextjs): Instrument server-sidegetInitialPropsof_app,_documentand_error#5604)Connected Traces
redirectandnotFoundresponses fromgetServerSideProps(alsogetStaticProps?)) (feat(nextjs): Connect trace between data-fetching methods and pageload #5655)isPrefetchRequest: booleantag to errors and do the one or more of the following to transactions 1. different name 2. data field 3. different op) (there is apurpose: prefetchheader in those requests)getServerSidePropspage that throws: Transaction name is/_errorbut DSC contains route ofgetServerSideProps. (SeeTODOcomment in src/performance/client.ts) ([nextjs] Fix transaction name getting lost when hitting_errorpage #5826)Serverside Transaction improvements
Currently, 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.
getInitialPropsandgetServerSideProps(feat(nextjs): Create transactions ingetInitialPropsandgetServerSideProps#5593)RequestDataintegration to work for error events (ref(nextjs): UseRequestDataintegration for errors #5729)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?)withSentryinto a wrapper/helper)res.sendsimilar to how we do it inwithSentry(ref(nextjs): Use flush code fromwithSentryin all backend wrappers #5814)Figure out how to propagate scope between data-fetching functions in the same transaction (ordocument scope-propagation limitations)instrumentServer.ts?statusto transactions and spans and update to "internal_error" on error (feat(nextjs): Add status to data-fetcher spans #5777)What happens for pages with no data fetchers? Should_apphave a different helper? (no name for transaction)Folow-up/Cleanup/Polishing
package.json(chore(nextjs): Remove obsoletedataFetchersloader #5713)RequestDataintegration everywhereCheck if new model works with CJS, if no, support people that use CJSwithSentryinto the fold (consolidate helpers)Documentation
RequestDataintegration and optionsMisc (stretch goals)
getInitialPropswhen run client-sideSteps for Beta
autoInstrumentServerFunctionssentry-docs#5542)withSentryfunction inwith-sentryexample vercel/next.js#41326)Steps for GA (Planned date: October 5, 2022)
autoInstrumentServerFunctionsper default #5919)withSentry(Remove references to manually usewithSentryfrom Next.js docs sentry-docs#5543)Follow ups
Undone tasks from above have been sorted into:
withSentryand possiblyinstrumentServer(JS SDK v8 Deprecations List #5194)_errorbetter ([nextjs] Fix transaction name getting lost when hitting_errorpage #5826)RequestDataintegration (RequestData integration prework, work, and postwork #5756)