What is @sentry/nextjs?
The @sentry/nextjs package is a JavaScript SDK for Sentry that provides error tracking and performance monitoring specifically tailored for Next.js applications. It helps developers to automatically capture exceptions, track performance issues, and improve the reliability of their Next.js applications.
What are @sentry/nextjs's main functionalities?
Automatic Error Tracking
Automatically captures unhandled exceptions and errors in the Next.js application and sends them to Sentry for monitoring and analysis.
import * as Sentry from '@sentry/nextjs';
Sentry.init({ dsn: 'YOUR_DSN' });
Performance Monitoring
Enables performance monitoring to track the performance of server-side and client-side Next.js operations, providing insights into slow transactions and bottlenecks.
import * as Sentry from '@sentry/nextjs';
Sentry.init({
dsn: 'YOUR_DSN',
tracesSampleRate: 1.0
});
Custom Error Reporting
Allows developers to manually report custom errors or exceptions to Sentry, giving them control over what gets reported.
import * as Sentry from '@sentry/nextjs';
Sentry.captureException(new Error('Custom error message'));
Release Health Tracking
Tracks the health of releases by monitoring error rates and issues that affect end-users, helping developers to understand the impact of new releases.
import * as Sentry from '@sentry/nextjs';
Sentry.init({
dsn: 'YOUR_DSN',
release: 'my-project-name@1.0.0'
});
Other packages similar to @sentry/nextjs
bugsnag-js
Bugsnag provides error monitoring for JavaScript applications, including Next.js. It offers similar features to Sentry, such as automatic error detection, custom error reporting, and release tracking. However, Bugsnag's interface and integrations may differ from Sentry's.
raygun4js
Raygun offers real-time error tracking and crash reporting for JavaScript applications. It includes features like user tracking, performance monitoring, and deployment tracking. Raygun's focus on user-centric metrics and detailed diagnostics provides a different perspective compared to Sentry.
logrocket
LogRocket is a frontend application monitoring solution that combines session replay, performance monitoring, and error tracking. Unlike Sentry, which focuses on error and performance data, LogRocket provides insights into user interactions and experiences by recording user sessions.
Official Sentry SDK for Next.js
See the Official Sentry Next.js SDK Docs to get started.
Compatibility
Currently, the minimum supported version of Next.js is 13.2.0
.
Installation
To get started installing the SDK, use the Sentry Next.js Wizard by running the following command in your terminal or
read the Getting Started Docs:
npx @sentry/wizard@latest -i nextjs
The wizard will prompt you to log in to Sentry. After the wizard setup is completed, the SDK will automatically capture
unhandled errors, and monitor performance.
Custom Usage
To set context information or to send manual events, you can use @sentry/nextjs
as follows:
import * as Sentry from '@sentry/nextjs';
Sentry.setTag('user_mode', 'admin');
Sentry.setUser({ id: '4711' });
Sentry.setContext('application_area', { location: 'checkout' });
Sentry.addBreadcrumb({
message: '"Add to cart" clicked',
});
Sentry.captureException(new Error('Oh no.'));
Sentry.captureMessage('Hello, world!');
Links
8.31.0
Important Changes
- feat(node): Add
dataloader
integration (#13664)
This release adds a new integration for the dataloader
package. The Node
SDK (and all SDKs that depend on it) will now automatically instrument dataloader
instances. You can also add it
manually:
Sentry.init({
integrations: [Sentry.dataloaderIntegration()],
});
Other Changes
- feat(browser): Add navigation
activationStart
timestamp to pageload span (#13658) - feat(gatsby): Add optional
deleteSourcemapsAfterUpload
(#13610) - feat(nextjs): Give app router prefetch requests a
http.server.prefetch
op (#13600) - feat(nextjs): Improve Next.js serverside span data quality (#13652)
- feat(node): Add
disableInstrumentationWarnings
option (#13693) - feat(nuxt): Adding
experimental_basicServerTracing
option to Nuxt module (#13643) - feat(nuxt): Improve logs about adding Node option 'import' (#13726)
- feat(replay): Add
onError
callback + other small improvements to debugging (#13721) - feat(replay): Add experimental option to allow for a checkout every 6 minutes (#13069)
- feat(wasm): Unconditionally parse instruction addresses (#13655)
- fix: Ensure all logs are wrapped with
consoleSandbox
(#13690) - fix(browser): Try multiple options for
lazyLoadIntegration
script parent element lookup (#13717) - fix(feedback): Actor color applies to feedback icon (#13702)
- fix(feedback): Fix form width on mobile devices (#13068)
- fix(nestjs): Preserve original function name on
SentryTraced
functions (#13684) - fix(node): Don't overwrite local variables for re-thrown errors (#13644)
- fix(normalize): Treat Infinity as NaN both are non-serializable numbers (#13406)
- fix(nuxt): Use correct server output file path (#13725)
- fix(opentelemetry): Always use active span in
Propagator.inject
(#13381) - fix(replay): Fixes potential out-of-order segments (#13609)
Work in this release was contributed by @KyGuy2002, @artzhookov, and @julianCast. Thank you for your contributions!