|
10 | 10 | [](https://www.npmjs.com/package/@sentry/nextjs)
|
11 | 11 | [](https://www.npmjs.com/package/@sentry/nextjs)
|
12 | 12 |
|
13 |
| -## Links |
14 |
| - |
15 |
| -- [Official SDK Docs](https://docs.sentry.io/platforms/javascript/guides/nextjs/) |
16 |
| -- [TypeDoc](http://getsentry.github.io/sentry-javascript/) |
| 13 | +> See the [Official Sentry Next.js SDK Docs](https://docs.sentry.io/platforms/javascript/guides/nextjs/) to get started. |
17 | 14 |
|
18 | 15 | ## Compatibility
|
19 | 16 |
|
20 |
| -Currently, the minimum Next.js supported version is `11.2.0`. |
21 |
| - |
22 |
| -## General |
23 |
| - |
24 |
| -This package is a wrapper around `@sentry/node` for the server and `@sentry/react` for the client, with added |
25 |
| -functionality related to Next.js. |
26 |
| - |
27 |
| -To use this SDK, initialize it in the Next.js configuration, in the `sentry.client.config.ts|js` file, and in the |
28 |
| -[Next.js Instrumentation Hook](https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation) |
29 |
| -(`instrumentation.ts|js`). |
| 17 | +Currently, the minimum supported version of Next.js is `13.2.0`. |
30 | 18 |
|
31 |
| -```javascript |
32 |
| -// next.config.js |
| 19 | +## Installation |
33 | 20 |
|
34 |
| -const { withSentryConfig } = require('@sentry/nextjs'); |
| 21 | +To get started installing the SDK, use the Sentry Next.js Wizard by running the following command in your terminal or |
| 22 | +read the [Getting Started Docs](https://docs.sentry.io/platforms/javascript/guides/nextjs/): |
35 | 23 |
|
36 |
| -const nextConfig = { |
37 |
| - experimental: { |
38 |
| - // The instrumentation hook is required for Sentry to work on the serverside |
39 |
| - instrumentationHook: true, |
40 |
| - }, |
41 |
| -}; |
42 |
| - |
43 |
| -// Wrap the Next.js configuration with Sentry |
44 |
| -module.exports = withSentryConfig(nextConfig); |
| 24 | +```sh |
| 25 | +npx @sentry/wizard@latest -i nextjs |
45 | 26 | ```
|
46 | 27 |
|
47 |
| -```javascript |
48 |
| -// sentry.client.config.js or .ts |
49 |
| - |
50 |
| -import * as Sentry from '@sentry/nextjs'; |
| 28 | +The wizard will prompt you to log in to Sentry. After the wizard setup is completed, the SDK will automatically capture |
| 29 | +unhandled errors, and monitor performance. |
51 | 30 |
|
52 |
| -Sentry.init({ |
53 |
| - dsn: '__DSN__', |
54 |
| - // Your Sentry configuration for the Browser... |
55 |
| -}); |
56 |
| -``` |
| 31 | +## Custom Usage |
57 | 32 |
|
58 |
| -```javascript |
59 |
| -// instrumentation.ts |
| 33 | +To set context information or to send manual events, you can use `@sentry/nextjs` as follows: |
60 | 34 |
|
61 |
| -import * as Sentry from '@sentry/nextjs'; |
62 |
| - |
63 |
| -export function register() { |
64 |
| - if (process.env.NEXT_RUNTIME === 'nodejs') { |
65 |
| - Sentry.init({ |
66 |
| - dsn: '__DSN__', |
67 |
| - // Your Node.js Sentry configuration... |
68 |
| - }); |
69 |
| - } |
70 |
| - |
71 |
| - if (process.env.NEXT_RUNTIME === 'edge') { |
72 |
| - Sentry.init({ |
73 |
| - dsn: '__DSN__', |
74 |
| - // Your Edge Runtime Sentry configuration... |
75 |
| - }); |
76 |
| - } |
77 |
| -} |
78 |
| -``` |
79 |
| - |
80 |
| -To set context information or send manual events, use the exported functions of `@sentry/nextjs`. |
81 |
| - |
82 |
| -```javascript |
| 35 | +```ts |
83 | 36 | import * as Sentry from '@sentry/nextjs';
|
84 | 37 |
|
85 | 38 | // Set user information, as well as tags and further extras
|
86 |
| -Sentry.setExtra('battery', 0.7); |
87 | 39 | Sentry.setTag('user_mode', 'admin');
|
88 | 40 | Sentry.setUser({ id: '4711' });
|
| 41 | +Sentry.setContext('application_area', { location: 'checkout' }); |
89 | 42 |
|
90 | 43 | // Add a breadcrumb for future events
|
91 | 44 | Sentry.addBreadcrumb({
|
92 |
| - message: 'My Breadcrumb', |
| 45 | + message: '"Add to cart" clicked', |
93 | 46 | // ...
|
94 | 47 | });
|
95 | 48 |
|
96 |
| -// Capture exceptions, messages or manual events |
| 49 | +// Capture exceptions or messages |
| 50 | +Sentry.captureException(new Error('Oh no.')); |
97 | 51 | Sentry.captureMessage('Hello, world!');
|
98 |
| -Sentry.captureException(new Error('Good bye')); |
99 |
| -Sentry.captureEvent({ |
100 |
| - message: 'Manual', |
101 |
| - stacktrace: [ |
102 |
| - // ... |
103 |
| - ], |
104 |
| -}); |
105 | 52 | ```
|
| 53 | + |
| 54 | +## Links |
| 55 | + |
| 56 | +- [Official SDK Docs](https://docs.sentry.io/platforms/javascript/guides/nextjs/) |
| 57 | +- [Sentry.io](https://sentry.io/?utm_source=github&utm_medium=npm_nextjs) |
| 58 | +- [Sentry Discord Server](https://discord.gg/Ww9hbqr) |
| 59 | +- [Stack Overflow](https://stackoverflow.com/questions/tagged/sentry) |
0 commit comments