✨ NextJS Add addNextJSError component#4308
Conversation
- Rename test app from `nextjs-app-router` to `nextjs` to reflect it now contains both App Router and Pages Router code - Add Pages Router error-test page using `NextjsErrorBoundary` with trigger/reset UI - Add `pages/_error.tsx` custom error page calling `addNextjsError` via `useEffect` - Add `pages-router/throw-error` page (SSR throw via `getServerSideProps`) to trigger `_error.tsx` - Add `app/global-error-test/page.tsx` that throws when `?throw=true` to trigger `global-error.tsx` - Add navigation links in Pages Router home and App Router home to reach new test pages - Restructure `nextjsPlugin.scenario.ts` into "router" and "errors" describe blocks, loop over `routerConfigs` - Export `isContinuousIntegration` from `test/e2e/lib/framework/index.ts` - Fix `eslint.config.mjs` path reference (`nextjs-app-router` → `nextjs`)
Bundles Sizes Evolution
🚀 CPU Performance
🧠 Memory Performance
|
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: f7678cb | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback! |
|
@codex pls review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 673952b723
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
1f87375 to
f7678cb
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f7678cbe8b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| source_type: 'browser', | ||
| csp: rawError.csp, | ||
| }, | ||
| context: { ...context, ...rawError.context, framework: 'nextjs', ...nextjsExtra }, |
There was a problem hiding this comment.
Sanitize user context before sending addNextjsError event
This path spreads context directly into the raw RUM event, but unlike rumPublicApi.addError it never calls sanitize first. When callers pass non-serializable values (for example circular objects or framework objects inside context), event serialization can fall back to '<error: unable to serialize object>', which can make the emitted line invalid and effectively drop the error payload instead of reporting it. Sanitizing the provided context before building context keeps addNextjsError behavior aligned with the core API.
Useful? React with 👍 / 👎.
| source_type: 'browser', | ||
| csp: rawError.csp, | ||
| }, | ||
| context: { ...context, ...rawError.context, framework: 'nextjs', ...nextjsExtra }, |
There was a problem hiding this comment.
Preserve caller context precedence when merging raw error context
The merge order here gives rawError.context (derived from error.dd_context) precedence over the explicit context argument, and does a shallow object spread. In collisions, caller-provided fields are overwritten (or nested fields are lost) even though the regular addError path uses combine(rawError.context, context) so explicit context wins and nested keys merge. This makes addNextjsError produce inconsistent context data for the same inputs.
Useful? React with 👍 / 👎.
Motivation
Discussed in this RFC specifically here
Changes
(AI written)
Adds
addNextjsError(error, context?)andNextjsErrorBoundaryto@datadog/browser-rum-nextjs— the integration points for reporting errors from Next.js error boundaries to Datadog RUM.addNextjsError(error, context?)framework: 'nextjs'contextnextjs.digestcontext when the error carries adigestproperty (server component errors — the hash links client-side errors to server-side logs)onRumStartdeferred callback so calls before SDK init are buffered and replayedframework,nextjs.digest) are always applied last in the context merge, so user-provided context cannot overwrite themNextjsErrorBoundaryaddNextjsErrorfor Pages Router client-side error catchingfallbackrender prop (NextjsErrorBoundaryFallback) and an optionalonErrorcallbackaddNextjsErrorincomponentDidCatchTest app & E2E
nextjs-app-router→nextjs(now covers both App Router and Pages Router)pages-router/index, user, guides, error boundary testNextjsErrorBoundarycatch + reset (pages router)Both APIs exported from
@datadog/browser-rum-nextjsmain entry.Test instructions
(AI written)
Navigating into
test/apps/nextjsyou can doyarn devoryarn start(for production) and use the developer extension to test the events.Checklist