Skip to content

✨ NextJS Add addNextJSError component#4308

Closed
BeltranBulbarellaDD wants to merge 7 commits intomainfrom
beltran.bulbarella/nextjs-addNextjsError2
Closed

✨ NextJS Add addNextJSError component#4308
BeltranBulbarellaDD wants to merge 7 commits intomainfrom
beltran.bulbarella/nextjs-addNextjsError2

Conversation

@BeltranBulbarellaDD
Copy link
Contributor

@BeltranBulbarellaDD BeltranBulbarellaDD commented Mar 10, 2026

Motivation

Discussed in this RFC specifically here

Changes

(AI written)

Adds addNextjsError(error, context?) and NextjsErrorBoundary to @datadog/browser-rum-nextjs — the integration points for reporting errors from Next.js error boundaries to Datadog RUM.

addNextjsError(error, context?)

  • Tags every error with framework: 'nextjs' context
  • Adds nextjs.digest context when the error carries a digest property (server component errors — the hash links client-side errors to server-side logs)
  • Uses onRumStart deferred callback so calls before SDK init are buffered and replayed
  • Reserved fields (framework, nextjs.digest) are always applied last in the context merge, so user-provided context cannot overwrite them

NextjsErrorBoundary

  • React class component wrapping addNextjsError for Pages Router client-side error catching
  • Accepts a fallback render prop (NextjsErrorBoundaryFallback) and an optional onError callback
  • Automatically calls addNextjsError in componentDidCatch

Test app & E2E

  • Renamed test app from nextjs-app-routernextjs (now covers both App Router and Pages Router)
  • Added Pages Router test pages: pages-router/ index, user, guides, error boundary test
  • E2E scenarios cover: router navigation (app + pages), client error (app + pages), server error with digest (app router), global error (app router), NextjsErrorBoundary catch + reset (pages router)

Both APIs exported from @datadog/browser-rum-nextjs main entry.

Test instructions

(AI written)

# Unit tests
yarn test:unit --spec packages/rum-nextjs/src/domain/error/addNextjsError.spec.ts

# E2E tests
yarn test:e2e -g "nextjs"

Navigating into test/apps/nextjs you can do yarn dev or yarn start (for production) and use the developer extension to test the events.

Checklist

  • Tested locally
  • Tested on staging
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.
  • Updated documentation and/or relevant AGENTS.md file

- 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`)
@BeltranBulbarellaDD BeltranBulbarellaDD changed the title Beltran.bulbarella/nextjs add nextjs error2 ✨ NextJS Add addNextJSError component Mar 10, 2026
@cit-pr-commenter-54b7da
Copy link

cit-pr-commenter-54b7da bot commented Mar 10, 2026

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 174.53 KiB 174.54 KiB +20 B +0.01%
Rum Profiler 6.16 KiB 6.16 KiB 0 B 0.00%
Rum Recorder 27.46 KiB 27.46 KiB 0 B 0.00%
Logs 56.84 KiB 56.84 KiB 0 B 0.00%
Flagging 944 B 944 B 0 B 0.00%
Rum Slim 130.21 KiB 130.23 KiB +20 B +0.02%
Worker 23.63 KiB 23.63 KiB 0 B 0.00%
🚀 CPU Performance
Action Name Base CPU Time (ms) Local CPU Time (ms) 𝚫%
addglobalcontext N/A 0.0047 N/A
addaction N/A 0.0158 N/A
adderror N/A 0.0141 N/A
addtiming N/A 0.003 N/A
startview N/A 0.0139 N/A
startstopsessionreplayrecording N/A 0.0007 N/A
logmessage N/A 0.0165 N/A
🧠 Memory Performance
Action Name Base Memory Consumption Local Memory Consumption 𝚫
addglobalcontext N/A 27.41 KiB N/A
addaction N/A 51.57 KiB N/A
addtiming N/A 26.13 KiB N/A
adderror N/A 55.37 KiB N/A
startstopsessionreplayrecording N/A 25.57 KiB N/A
startview N/A 448.19 KiB N/A
logmessage N/A 44.66 KiB N/A

🔗 RealWorld

@datadog-prod-us1-3
Copy link

datadog-prod-us1-3 bot commented Mar 10, 2026

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 92.00%
Overall Coverage: 77.29% (+0.07%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 586c754 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback!

@BeltranBulbarellaDD
Copy link
Contributor Author

@codex pls review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

@BeltranBulbarellaDD BeltranBulbarellaDD force-pushed the beltran.bulbarella/nextjs-addNextjsError2 branch from 1f87375 to f7678cb Compare March 11, 2026 10:54
@BeltranBulbarellaDD BeltranBulbarellaDD marked this pull request as ready for review March 11, 2026 11:17
@BeltranBulbarellaDD BeltranBulbarellaDD requested a review from a team as a code owner March 11, 2026 11:17
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

@BeltranBulbarellaDD BeltranBulbarellaDD requested a review from a team as a code owner March 11, 2026 12:27

Next.js uses [error boundaries][2] (`error.tsx` files) to catch uncaught exceptions in each route segment. Use `addNextjsError` inside these boundaries to report errors to Datadog RUM.

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
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 `error.digest` is absent.

Is the digest listed here meant to be the error.digest listed earlier?

If yes, I recommend writing it out fully to avoid any confusion.

If no, feel free to dismiss this comment. But I'd recommend clarifying where this digest originates/is used, since we are saying it is absent in this circumstance.

Let me know if you have any questions!

Copy link

@iadjivon iadjivon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi there,
Thanks for sharing this PR with the Doc team!
I've approved this with a small comment.
Let us know if you have any questions!

@BeltranBulbarellaDD BeltranBulbarellaDD marked this pull request as draft March 12, 2026 10:56
@github-actions github-actions bot locked and limited conversation to collaborators Mar 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants