Skip to content

Improve Nextjs tracing #5505

Closed
Closed
@smeubank

Description

@smeubank

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

  • ⚠️ Remove MVP loader code and remove its dependencies from package.json (chore(nextjs): Remove obsolete dataFetchers loader #5713)
  • Use RequestData integration everywhere
  • Check if new model works with CJS, if no, support people that use CJS
  • ⚠️ 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)
  • Bring withSentry into the fold (consolidate helpers)
  • Nudge users to stop wrapping API routes if using auto-wrapping (once auto-wrapping includes API routes)
  • Factor more common parts out of wrappers if possible

Documentation

  • Document new RequestData integration and options
  • Document auto-wrapping

Misc (stretch goals)

  • Have spans for getInitialProps when run client-side
  • Add instrumentation for how long server-side rendering takes
  • Investigate how it would be possible to support custom servers
  • Can common route-handling work be consolidated into helper functions across frameworks, so we're not always reinventing the wheel?

Steps for Beta

Steps for GA (Planned date: October 5, 2022)


Follow ups

Undone tasks from above have been sorted into:

Metadata

Metadata

Labels

Package: nextjsIssues related to the Sentry Nextjs SDK

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions