Skip to content

Commit 6cb0f69

Browse files
Edit NextJS RUM Integration README
1 parent bae987f commit 6cb0f69

File tree

1 file changed

+47
-53
lines changed

1 file changed

+47
-53
lines changed

rum_nextjs/README.md

Lines changed: 47 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
11
# RUM Browser Monitoring - NEXTJS integration
22

3-
> **Note**: This integration is in beta. Features and configuration may change.
4-
53
## Overview
64

7-
With the Datadog RUM Next.js integration, resolve performance issues quickly in Next.js applications by:
8-
9-
- Debugging the root cause of performance bottlenecks, such as a slow server response time, render-blocking resource, or an error inside a component
10-
- Automatically correlating web performance data with user journeys, HTTP calls, and logs
11-
- Alerting your engineering teams when crucial web performance metrics (such as Core Web Vitals) fall below a threshold that results in a poor user experience
5+
The Datadog RUM Next.js integration provides framework-specific instrumentation to help you monitor and debug Next.js applications. This integration adds:
126

13-
Monitor your Next.js applications from end-to-end by:
7+
- **Automatic route change detection** for both the App Router and Pages Router
8+
- **View name normalization** that converts dynamic route segments into parameterized names (e.g. `/users/123` becomes `/users/[id]`)
9+
- **Error reporting** with built-in components for Next.js error boundaries
10+
- **Full-stack visibility** by correlating frontend performance with backend traces and logs
1411

15-
- Tracking and visualizing user journeys across your entire stack with automatic route change detection for both the App Router and Pages Router
16-
- Automatically normalizing dynamic route segments into parameterized view names (e.g. `/users/123` to `/users/[id]`)
17-
- Analyzing and contextualizing every user session with attributes such as user ID, email, name, and more
18-
- Unifying full-stack monitoring in one platform for frontend and backend development teams
12+
Combined with Datadog RUM's core capabilities, you can debug performance bottlenecks, track user journeys, monitor Core Web Vitals, and analyze every user session with context.
1913

2014
## Setup
2115

22-
Start by setting up [Datadog RUM][2] in your Next.js application. If you're creating a new RUM application in the Datadog App, select Next.js as the application type. If you already have an existing RUM application, you can update its type to Next.js instead. Once configured, the Datadog App will provide instructions for integrating the [RUM-Next.js plugin][8] with the Browser SDK. If Next.js is not available as an option, select React and follow the steps below to integrate the plugin manually.
16+
Start by setting up [Datadog RUM][1] in your Next.js application:
17+
18+
- If you are creating a RUM application, select **Next.js** as the application type.
19+
- If Next.js is not available as an option, select **React** and follow the steps below to integrate the plugin manually.
20+
21+
After configuration, the Datadog App provides instructions for integrating the [RUM-Next.js plugin][2] with the Browser SDK.
2322

24-
Both routers require **Next.js v15.3+**, which supports the [`instrumentation-client`][1] file convention.
23+
Both routers require **Next.js v15.3+**, which supports the [`instrumentation-client`][3] file convention.
2524

26-
# App Router Usage
25+
## App router usage
2726

28-
## 1. Create an `instrumentation-client.js` file in the root of your Next.js project
27+
### 1. Create an `instrumentation-client.js` file in the root of your Next.js project
2928

3029
Initialize the Datadog RUM SDK with the `nextjsPlugin` and re-export `onRouterTransitionStart` so Next.js can call it on client-side navigations:
3130

@@ -43,7 +42,7 @@ datadogRum.init({
4342
})
4443
```
4544

46-
## 2. Call the DatadogAppRouter component from your root layout.
45+
### 2. Call the DatadogAppRouter component from your root layout.
4746

4847
```tsx
4948
// app/layout.tsx
@@ -61,7 +60,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
6160
}
6261
```
6362

64-
## 3. Report errors from error boundaries
63+
### 3. Report errors from error boundaries
6564

6665
Next.js uses [error boundaries](https://nextjs.org/docs/app/api-reference/file-conventions/error) (`error.tsx` files) to catch uncaught exceptions in each route segment. Use `addNextjsError` inside these boundaries to report errors to Datadog RUM.
6766

@@ -107,9 +106,9 @@ export default function GlobalError({ error, reset }: { error: Error & { digest?
107106
}
108107
```
109108

110-
# Pages Router Usage
109+
## Pages router usage
111110

112-
## 1. Create an `instrumentation-client.js` file in the root of your Next.js project
111+
### 1. Create an `instrumentation-client.js` file in the root of your Next.js project
113112

114113
Initialize the Datadog RUM SDK with the `nextjsPlugin`. The `onRouterTransitionStart` export is **not needed** for Pages Router.
115114

@@ -125,7 +124,7 @@ datadogRum.init({
125124
})
126125
```
127126

128-
## 2. Call the DatadogPagesRouter component from your custom App.
127+
### 2. Call the DatadogPagesRouter component from your custom App.
129128

130129
```tsx
131130
// pages/_app.tsx
@@ -142,7 +141,7 @@ export default function MyApp({ Component, pageProps }: AppProps) {
142141
}
143142
```
144143

145-
## 3. Report errors from error boundaries
144+
### 3. Report errors from error boundaries
146145

147146
Use the `ErrorBoundary` component in your custom App to catch React rendering errors and report them to Datadog RUM:
148147

@@ -155,59 +154,54 @@ export default function MyApp({ Component, pageProps }: AppProps) {
155154
return (
156155
<>
157156
<DatadogPagesRouter />
158-
<ErrorBoundary fallback={({ resetError }) => (
159-
<div>
160-
<p>Something went wrong</p>
161-
<button onClick={resetError}>Try again</button>
162-
</div>
163-
)}>
157+
<ErrorBoundary
158+
fallback={({ resetError }) => (
159+
<div>
160+
<p>Something went wrong</p>
161+
<button onClick={resetError}>Try again</button>
162+
</div>
163+
)}
164+
>
164165
<Component {...pageProps} />
165166
</ErrorBoundary>
166167
</>
167168
)
168169
}
169170
```
170171

171-
## Route Tracking
172+
## Route tracking
172173

173174
The `DatadogPagesRouter` and `DatadogAppRouter` components automatically track route changes and normalize dynamic segments into parameterized view names:
174175

175-
| Actual URL | View name |
176-
|---|---|
177-
| `/about` | `/about` |
178-
| `/users/123` | `/users/[id]` |
176+
| Actual URL | View name |
177+
| ---------------------- | -------------------------------- |
178+
| `/about` | `/about` |
179+
| `/users/123` | `/users/[id]` |
179180
| `/users/123/posts/456` | `/users/[userId]/posts/[postId]` |
180-
| `/docs/a/b/c` | `/docs/[...slug]` |
181+
| `/docs/a/b/c` | `/docs/[...slug]` |
181182

182-
## Go Further with Datadog Next.js Integration
183+
## Go further with Datadog Next.js integration
183184

184185
### Traces
185186

186-
Connect your RUM and trace data to get a complete view of your application's performance. See [Connect RUM and Traces][3].
187+
Connect your RUM and trace data to get a complete view of your application's performance. See [Connect RUM and Traces][4].
187188

188189
### Logs
189190

190-
To start forwarding your Next.js application's logs to Datadog, see [JavaScript Logs Collection][4].
191+
To forward your Next.js application's logs to Datadog, see [JavaScript Logs Collection][5].
191192

192193
### Metrics
193194

194-
To generate custom metrics from your RUM application, see [Generate Metrics][5].
195+
To generate custom metrics from your RUM application, see [Generate Metrics][6].
195196

196197
## Troubleshooting
197198

198-
Need help? Contact [Datadog Support][6].
199-
200-
## Further Reading
201-
202-
Additional helpful documentation, links, and articles:
203-
204-
- [Next.js Monitoring][7]
199+
Need help? Contact [Datadog Support][7].
205200

206-
[1]: https://nextjs.org/docs/app/api-reference/file-conventions/instrumentation-client
207-
[2]: https://docs.datadoghq.com/real_user_monitoring/browser/setup/client
208-
[3]: https://docs.datadoghq.com/real_user_monitoring/platform/connect_rum_and_traces/?tab=browserrum
209-
[4]: https://docs.datadoghq.com/logs/log_collection/javascript/
210-
[5]: https://docs.datadoghq.com/real_user_monitoring/generate_metrics
211-
[6]: https://docs.datadoghq.com/help/
212-
[7]: https://docs.datadoghq.com/real_user_monitoring/browser/monitoring_page_performance/
213-
[8]: https://www.npmjs.com/package/@datadog/browser-rum-nextjs
201+
[1]: https://docs.datadoghq.com/real_user_monitoring/browser/setup/client
202+
[2]: https://www.npmjs.com/package/@datadog/browser-rum-nextjs
203+
[3]: https://nextjs.org/docs/app/api-reference/file-conventions/instrumentation-client
204+
[4]: https://docs.datadoghq.com/real_user_monitoring/platform/connect_rum_and_traces/?tab=browserrum
205+
[5]: https://docs.datadoghq.com/logs/log_collection/javascript/
206+
[6]: https://docs.datadoghq.com/real_user_monitoring/generate_metrics
207+
[7]: https://docs.datadoghq.com/help/

0 commit comments

Comments
 (0)