|
7 | 7 |
|
8 | 8 | # Official Sentry SDK for NextJS
|
9 | 9 |
|
10 |
| -TODO: npm version, npm dm, npm dt, typedoc |
11 |
| - |
12 | 10 | ## Links
|
13 | 11 |
|
14 | 12 | - [Official SDK Docs](https://docs.sentry.io/quickstart/)
|
15 | 13 | - [TypeDoc](http://getsentry.github.io/sentry-javascript/)
|
16 | 14 |
|
17 |
| -## Usage |
| 15 | +## General |
| 16 | + |
| 17 | +This package is a wrapper around `@sentry/node` for the server and `@sentry/react` for the client, with added functionality related to NextJS. |
| 18 | + |
| 19 | +To use this SDK, call `Sentry.init(options)` as early as possible in the server and the client; |
| 20 | +this will initialize the SDK and hook into the environment. |
| 21 | + |
| 22 | + |
| 23 | +```javascript |
| 24 | +import * as Sentry from '@sentry/nextjs'; |
| 25 | + |
| 26 | +Sentry.init({ |
| 27 | + dsn: '__DSN__', |
| 28 | + // ... |
| 29 | +}); |
| 30 | +``` |
| 31 | + |
| 32 | +To set context information or send manual events, use the exported functions of `@sentry/minimal`. |
| 33 | +Note that these functions will not perform any action before you have called `Sentry.init()`: |
| 34 | + |
| 35 | +```javascript |
| 36 | +import * as Sentry from '@sentry/nextjs'; |
| 37 | + |
| 38 | +// Set user information, as well as tags and further extras |
| 39 | +Sentry.configureScope(scope => { |
| 40 | + scope.setExtra('battery', 0.7); |
| 41 | + scope.setTag('user_mode', 'admin'); |
| 42 | + scope.setUser({ id: '4711' }); |
| 43 | + // scope.clear(); |
| 44 | +}); |
| 45 | + |
| 46 | +// Add a breadcrumb for future events |
| 47 | +Sentry.addBreadcrumb({ |
| 48 | + message: 'My Breadcrumb', |
| 49 | + // ... |
| 50 | +}); |
18 | 51 |
|
19 |
| -TODO |
| 52 | +// Capture exceptions, messages or manual events |
| 53 | +Sentry.captureMessage('Hello, world!'); |
| 54 | +Sentry.captureException(new Error('Good bye')); |
| 55 | +Sentry.captureEvent({ |
| 56 | + message: 'Manual', |
| 57 | + stacktrace: [ |
| 58 | + // ... |
| 59 | + ], |
| 60 | +});``` |
0 commit comments