Skip to content

Commit d19247a

Browse files
codydeclaude
andcommitted
Next.js: Centralize documentation flow with error handling
Improves Next.js integration documentation with centralized guidance and comprehensive error handling: ## Documentation Improvements - Streamlined installation wizard flow with clearer feature selection - Enhanced configuration examples with detailed explanations - Improved error handling setup for both App Router and Pages Router - Better organized verification steps and troubleshooting ## Error Handling Components Added - App Router global error boundary examples - Pages Router error page templates - Nested server component error handling - Comprehensive error capture strategies ## Platform Includes Added - Next.js-specific tracing step 1 (enable) - Next.js-specific tracing step 2 (distributed) - Error handling templates for different Next.js patterns 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent d80be14 commit d19247a

File tree

7 files changed

+363
-162
lines changed

7 files changed

+363
-162
lines changed

docs/platforms/javascript/guides/nextjs/index.mdx

Lines changed: 151 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,25 @@ categories:
1717

1818
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/).
1919

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 <PlatformLink to="/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.
2123

2224
<OnboardingOptionButtons
2325
options={[
24-
"error-monitoring",
25-
"performance",
26-
"session-replay",
27-
"user-feedback",
28-
"logs",
26+
{id: "error-monitoring", checked: true, disabled: true},
27+
{id: "performance", checked: true},
28+
{id: "session-replay", checked: true},
29+
{id: "user-feedback", checked: false},
30+
{id: "logs", checked: true},
2931
]}
3032
/>
3133

32-
## Step 1: Install
34+
## Install
35+
36+
Run the command for your preferred path to add Sentry to your application.
3337

34-
To install Sentry using the installation wizard, run the following command within your project:
38+
### Use the Installation Wizard (Recommended)
3539

3640
```bash
3741
npx @sentry/wizard@latest -i nextjs
@@ -41,8 +45,6 @@ The wizard then guides you through the setup process, asking you to enable addit
4145

4246
<PlatformContent includePath="getting-started-features-expandable" />
4347

44-
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.
45-
4648
<Expandable title="What does the installation wizard change inside your application?">
4749

4850
- Creates config files with the default `Sentry.init()` calls for all runtimes (Node.js, Browser, and Edge)
@@ -54,9 +56,9 @@ This guide assumes that you enable all features and allow the wizard to create a
5456

5557
</Expandable>
5658

57-
## Step 2: Configure
59+
## Configure
5860

59-
If you prefer to configure Sentry manually, here are the configuration files the wizard would create:
61+
If you want to expand on your Sentry configuration by adding additional functionality, or manually instrument your application, here are the configuration files the wizard would create. Initialize Sentry as early as possible.
6062

6163
### Client-Side Configuration
6264

@@ -71,6 +73,9 @@ Sentry.init({
7173
sendDefaultPii: true,
7274

7375
integrations: [
76+
// ___PRODUCT_OPTION_START___ performance
77+
Sentry.browserTracingIntegration(),
78+
// ___PRODUCT_OPTION_END___ performance
7479
// ___PRODUCT_OPTION_START___ session-replay
7580
// Replay may only be enabled for the client-side
7681
Sentry.replayIntegration(),
@@ -105,10 +110,6 @@ Sentry.init({
105110
replaysOnErrorSampleRate: 1.0,
106111
// ___PRODUCT_OPTION_END___ session-replay
107112
});
108-
109-
// ___PRODUCT_OPTION_START___ performance
110-
export const onRouterTransitionStart = Sentry.captureRouterTransitionStart;
111-
// ___PRODUCT_OPTION_END___ performance
112113
```
113114

114115
### Server-Side Configuration
@@ -141,9 +142,137 @@ Sentry.init({
141142

142143
For detailed manual setup instructions, see our [manual setup guide](/platforms/javascript/guides/nextjs/manual-setup/).
143144

144-
## Step 3: Verify Your Setup
145+
## Capture Next.js Errors
145146

146-
<Include name="nextjs-turbopack-warning-expandable.mdx" />
147+
Make sure runtime errors are surfaced to Sentry using Next.js error components.
148+
149+
### App Router
150+
151+
<PlatformContent includePath="getting-started-capture-errors/app-router-global-error" />
152+
153+
#### Errors from Nested React Server Components
154+
155+
<PlatformContent includePath="getting-started-capture-errors/nested-server-components" />
156+
157+
### Pages Router
158+
159+
<PlatformContent includePath="getting-started-capture-errors/pages-router-error" />
160+
161+
<Alert level="info">
162+
The installation wizard will scaffold these files for you if they are missing.
163+
</Alert>
164+
165+
<OnboardingOption optionId="performance">
166+
167+
<OnboardingOption optionId="logs">
168+
169+
## Sending Logs
170+
171+
[Structured logging](/platforms/javascript/guides/nextjs/logs/) lets users send text-based log information from their applications to Sentry. Once in Sentry, these logs can be viewed alongside relevant errors, searched by text-string, or searched using their individual attributes.
172+
173+
Use Sentry's logger to capture structured logs with meaningful attributes that help you debug issues and understand user behavior.
174+
175+
```javascript
176+
import * as Sentry from "@sentry/nextjs";
177+
178+
const { logger } = Sentry;
179+
180+
logger.info("User completed checkout", {
181+
userId: 123,
182+
orderId: "order_456",
183+
amount: 99.99,
184+
});
185+
186+
logger.error("Payment processing failed", {
187+
errorCode: "CARD_DECLINED",
188+
userId: 123,
189+
attemptCount: 3,
190+
});
191+
192+
logger.warn(logger.fmt`Rate limit exceeded for user: ${123}`);
193+
```
194+
195+
</OnboardingOption>
196+
197+
<OnboardingOption optionId="session-replay">
198+
199+
## Customizing Replays
200+
201+
[Replays](/product/explore/session-replay/web/getting-started/) allow you to see video-like reproductions of user sessions.
202+
203+
By default, Session Replay masks sensitive data for privacy and to protect PII data. You can modify the replay configurations in your client-side Sentry initialization to show (unmask) specific content that's safe to display.
204+
205+
```javascript {filename:instrumentation-client.(js|ts)}
206+
import * as Sentry from "@sentry/nextjs";
207+
208+
Sentry.init({
209+
dsn: "___PUBLIC_DSN___",
210+
integrations: [
211+
Sentry.replayIntegration({
212+
// This will show the content of the div with the class "reveal-content" and the span with the data-safe-to-show attribute
213+
unmask: [".reveal-content", "[data-safe-to-show]"],
214+
// This will show all text content in replays. Use with caution.
215+
maskAllText: false,
216+
// This will show all media content in replays. Use with caution.
217+
blockAllMedia: false,
218+
}),
219+
],
220+
// Only capture replays for 10% of sessions
221+
replaysSessionSampleRate: 0.1,
222+
// Capture replays for 100% of sessions with an error
223+
replaysOnErrorSampleRate: 1.0,
224+
});
225+
```
226+
227+
```jsx
228+
<div className="reveal-content">This content will be visible in replays</div>
229+
<span data-safe-to-show>Safe user data</span>
230+
```
231+
232+
</OnboardingOption>
233+
234+
## Custom Traces with Attributes
235+
236+
[Tracing](/platforms/javascript/guides/nextjs/tracing/) allows you to monitor interactions between multiple services or applications. Create custom spans to measure specific operations and add meaningful attributes. This helps you understand performance bottlenecks and debug issues with detailed context.
237+
238+
```javascript
239+
import * as Sentry from "@sentry/nextjs";
240+
241+
async function processUserData(userId) {
242+
return await Sentry.startSpan(
243+
{
244+
name: "Process User Data",
245+
op: "function",
246+
attributes: {
247+
userId: userId,
248+
operation: "data_processing",
249+
version: "2.1",
250+
},
251+
},
252+
async () => {
253+
const userData = await fetch(`/api/user?id=${userId}`).then((r) => r.json());
254+
255+
return await Sentry.startSpan(
256+
{
257+
name: "Transform Data",
258+
op: "transform",
259+
attributes: { recordCount: userData.length, transformType: "normalize" },
260+
},
261+
() => transformUserData(userData)
262+
);
263+
}
264+
);
265+
}
266+
267+
const span = Sentry.getActiveSpan();
268+
if (span) {
269+
span.setAttributes({ cacheHit: true, region: "us-west-2", performanceScore: 0.95 });
270+
}
271+
```
272+
273+
</OnboardingOption>
274+
275+
## Verify Your Setup
147276

148277
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:
149278

@@ -169,6 +298,8 @@ Now, head over to your project on [Sentry.io](https://sentry.io) to view the col
169298

170299
<PlatformContent includePath="getting-started-verify-locate-data" />
171300

301+
<Include name="nextjs-turbopack-warning-expandable.mdx" />
302+
172303
## Next Steps
173304

174305
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.
@@ -182,6 +313,8 @@ Our next recommended steps for you are:
182313
- Get familiar with [Sentry's product features](/product) like tracing, insights, and alerts
183314
- Learn more about our [Vercel integration](/organization/integrations/deployment/vercel/)
184315

316+
<PlatformContent includePath="getting-started-features-expandable" />
317+
185318
<Expandable permalink={false} title="Are you having problems setting up the SDK?">
186319

187320
- If you encountered issues with our installation wizard, try [setting up Sentry manually](/platforms/javascript/guides/nextjs/manual-setup/)

0 commit comments

Comments
 (0)