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
The Datadog RUM Next.js integration provides framework-specific instrumentation to help you monitor and debug Next.js applications. This integration adds:
8
8
9
-
# App Router Usage
9
+
-**Automatic route change detection** for both the App Router and Pages Router
10
+
-**View name normalization** that converts dynamic route segments into parameterized names (e.g. `/users/123` becomes `/users/[id]`)
11
+
-**Error reporting** with built-in components for Next.js error boundaries
12
+
-**Full-stack visibility** by correlating frontend performance with backend traces and logs
10
13
11
-
## 1. Create an `instrumentation-client.js` file in the root of your Next.js project
14
+
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.
15
+
16
+
## Setup
17
+
18
+
Start by setting up [Datadog RUM][1] in your Next.js application:
19
+
20
+
- If you are creating a RUM application, select **Next.js** as the application type.
21
+
- If Next.js is not available as an option, select **React** and follow the steps below to integrate the plugin manually.
22
+
23
+
After configuration, the Datadog App provides instructions for integrating the [RUM-Next.js plugin][2] with the Browser SDK.
24
+
25
+
Both routers require **Next.js v15.3+**, which supports the [`instrumentation-client`][3] file convention.
26
+
27
+
## App router usage
28
+
29
+
### 1. Create an `instrumentation-client.js` file in the root of your Next.js project
12
30
13
31
Initialize the Datadog RUM SDK with the `nextjsPlugin` and re-export `onRouterTransitionStart` so Next.js can call it on client-side navigations:
14
32
@@ -26,7 +44,7 @@ datadogRum.init({
26
44
})
27
45
```
28
46
29
-
## 2. Call the DatadogAppRouter component from your root layout.
47
+
###2. Call the DatadogAppRouter component from your root layout.
30
48
31
49
```tsx
32
50
// app/layout.tsx
@@ -44,9 +62,55 @@ export default function RootLayout({ children }: { children: React.ReactNode })
44
62
}
45
63
```
46
64
47
-
# Pages Router Usage
65
+
### 3. Report errors from error boundaries
66
+
67
+
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.
68
+
69
+
For **Server Component** errors, Next.js sends a generic message to the client and attaches `error.digest`, a hash that links the client-side error to your server-side logs. For **Client Component** errors, `error.message` is the original message and `digest` is absent.
The `DatadogPagesRouter` and `DatadogAppRouter` components automatically track route changes and normalize dynamic segments into parameterized view names:
0 commit comments