You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enhance Next.js guide with structured logging and error handling instructions
- Added section on sending structured logs to Sentry.
- Updated installation instructions to clarify the use of the installation wizard and manual SDK installation.
- Included detailed steps for capturing Next.js errors using app and pages routers.
- Expanded on customizing session replays and creating custom traces with attributes.
- Added a new section for verifying the setup and included Turbopack support information.
In addition to capturing errors, you can monitor interactions between multiple services or applications by [enabling tracing](/concepts/key-terms/tracing/). You can also get to the root of an error or performance issue faster, by watching a video-like reproduction of a user session with [session replay](/product/explore/session-replay/web/getting-started/).
19
19
20
-
Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.
20
+
Send <PlatformLinkto="/platforms/javascript/guides/nextjs/logs/">structured logs</PlatformLink> to Sentry and correlate them with errors and traces.
21
+
22
+
Select which Sentry features you'd like to configure to get the corresponding setup instructions below.
21
23
22
24
<OnboardingOptionButtons
23
25
options={[
24
-
"error-monitoring",
25
-
"performance",
26
-
"session-replay",
27
-
"user-feedback",
28
-
"logs",
26
+
{id: "error-monitoring", checked: true},
27
+
{id: "performance", checked: true},
28
+
{id: "session-replay", checked: true},
29
+
{id: "user-feedback", checked: false},
30
+
{id: "logs", checked: true},
29
31
]}
30
32
/>
31
33
32
34
## Step 1: Install
33
35
34
-
To install Sentry using the installation wizard, run the following command within your project:
36
+
Run the command for your preferred path to add Sentry to your application.
37
+
38
+
### Use the Installation Wizard (Recommended)
35
39
36
40
```bash
37
41
npx @sentry/wizard@latest -i nextjs
38
42
```
39
43
40
-
The wizard then guides you through the setup process, asking you to enable additional (optional) Sentry features for your application beyond error monitoring.
44
+
The wizard guides you through setup and can enable optional features beyond error monitoring. This guide assumes that you enable all features and allow the wizard to create an example page and route. You can add or remove features at any time.
This guide assumes that you enable all features and allow the wizard to create an example page and route. You can add or remove features at any time, but setting them up now will save you the effort of configuring them manually later.
48
+
```bash {tabTitle:npm}
49
+
npm install @sentry/nextjs --save
50
+
```
51
+
52
+
```bash {tabTitle:yarn}
53
+
yarn add @sentry/nextjs
54
+
```
55
+
56
+
```bash {tabTitle:pnpm}
57
+
pnpm add @sentry/nextjs
58
+
```
45
59
46
60
<Expandabletitle="What does the installation wizard change inside your application?">
47
61
@@ -56,7 +70,7 @@ This guide assumes that you enable all features and allow the wizard to create a
56
70
57
71
## Step 2: Configure
58
72
59
-
If you prefer to configure Sentry manually, here are the configuration files the wizard would create:
73
+
If you prefer to configure Sentry manually, here are the configuration files the wizard would create. Initialize Sentry as early as possible.
60
74
61
75
### Client-Side Configuration
62
76
@@ -140,9 +154,152 @@ Sentry.init({
140
154
141
155
For detailed manual setup instructions, see our [manual setup guide](/platforms/javascript/guides/nextjs/manual-setup/).
The installation wizard will scaffold these files for you if they are missing.
197
+
</Alert>
198
+
199
+
<OnboardingOptionoptionId="performance">
200
+
201
+
<OnboardingOptionoptionId="logs">
202
+
203
+
## Step 4: Sending Logs
204
+
205
+
Now let's add structured logging to capture application insights. Logs are enabled in your configuration above.
206
+
207
+
Use Sentry's logger to capture structured logs with meaningful attributes that help you debug issues and understand user behavior.
208
+
209
+
```javascript
210
+
import*asSentryfrom"@sentry/nextjs";
211
+
212
+
const { logger } = Sentry;
213
+
214
+
logger.info("User completed checkout", {
215
+
userId:123,
216
+
orderId:"order_456",
217
+
amount:99.99,
218
+
});
219
+
220
+
logger.error("Payment processing failed", {
221
+
errorCode:"CARD_DECLINED",
222
+
userId:123,
223
+
attemptCount:3,
224
+
});
225
+
226
+
logger.warn(logger.fmt`Rate limit exceeded for user: ${123}`);
227
+
```
228
+
229
+
</OnboardingOption>
230
+
231
+
<OnboardingOptionoptionId="session-replay">
232
+
233
+
## Step 5: Customizing Replays
234
+
235
+
By default, Session Replay masks sensitive data for privacy. Customize this to show specific content that's safe to display by adjusting the client-side integration.
<div className="reveal-content">This content will be visible in replays</div>
256
+
<span data-safe-to-show>Safe user data</span>
257
+
```
258
+
259
+
</OnboardingOption>
260
+
261
+
## Step 6: Custom Traces with Attributes
262
+
263
+
Create custom spans to measure specific operations and add meaningful attributes. This helps you understand performance bottlenecks and debug issues with detailed context.
If you haven't tested your Sentry configuration yet, let's do it now. You can confirm that Sentry is working properly and sending data to your Sentry project by using the example page and route created by the installation wizard:
148
305
@@ -168,6 +325,10 @@ Now, head over to your project on [Sentry.io](https://sentry.io) to view the col
At this point, you should have integrated Sentry into your Next.js application and should already be sending error and performance data to your Sentry project.
@@ -181,6 +342,8 @@ Our next recommended steps for you are:
181
342
- Get familiar with [Sentry's product features](/product) like tracing, insights, and alerts
182
343
- Learn more about our [Vercel integration](/organization/integrations/deployment/vercel/)
0 commit comments