Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nextjs): Trace navigation transactions #5676

Merged
merged 15 commits into from Sep 6, 2022

Conversation

lforst
Copy link
Member

@lforst lforst commented Sep 1, 2022

Ref: #5505

Improves Next.js clientside tracing by starting transactions earlier. Previously, requests to Next.js data-fetchers were not instrumented with baggage and sentry-trace headers because the requests were done before the navigation transaction was even started.

To get earlier navigation transactions we make use of the routeChangeStart router event, which runs before the data fetching requests go out. Sadly, at that point in time, we have no real way of knowing which parameterized route the user will navigate to. To get around this, on navigation, we take a peek at the __BUILD_MANIFEST global that Next.js defines. It contains a list of all parameterized routes we can use to match the navigation target against.

@lforst lforst mentioned this pull request Sep 1, 2022
43 tasks
@github-actions
Copy link
Contributor

github-actions bot commented Sep 1, 2022

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 19.43 KB (-0.02% 🔽)
@sentry/browser - ES5 CDN Bundle (minified) 60.11 KB (0%)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 18 KB (+0.01% 🔺)
@sentry/browser - ES6 CDN Bundle (minified) 52.97 KB (0%)
@sentry/browser - Webpack (gzipped + minified) 19.8 KB (0%)
@sentry/browser - Webpack (minified) 64.36 KB (0%)
@sentry/react - Webpack (gzipped + minified) 19.82 KB (0%)
@sentry/nextjs Client - Webpack (gzipped + minified) 44.86 KB (+0.4% 🔺)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 25.93 KB (-0.01% 🔽)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 24.3 KB (-0.01% 🔽)

@lforst lforst marked this pull request as ready for review September 5, 2022 14:57
@lforst lforst changed the title feat(nextjs): Trace pageload transitions feat(nextjs): Trace navigation transactions Sep 5, 2022
}
}

function getNextRouteFromPathname(pathname: string): string | void {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not the biggest fan of union typing with void - can we just union type with undefined and have an early return? (see microsoft/TypeScript#42709 on some larger issues with void that I share similar opinions on)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course! TIL 53b5021

readyCalled = true;
return cb();
events: {
on(type: string, handler: (...args: any[]) => void) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we also test if off was called on the listener?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in a340b5c

@lforst lforst enabled auto-merge (squash) September 6, 2022 13:36
@lforst lforst merged commit 58c067e into master Sep 6, 2022
@lforst lforst deleted the lforst-traced-clientside-transitions branch September 6, 2022 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants