Skip to content

✨ NextJS- addNextjsError component#4343

Merged
BeltranBulbarellaDD merged 6 commits intomainfrom
beltran.bulbarella/nextjs_app_router_error
Mar 17, 2026
Merged

✨ NextJS- addNextjsError component#4343
BeltranBulbarellaDD merged 6 commits intomainfrom
beltran.bulbarella/nextjs_app_router_error

Conversation

@BeltranBulbarellaDD
Copy link
Copy Markdown
Contributor

Motivation

This PR adds error reporting support to @datadog/browser-rum-nextjs for the App Router.

Changes

packages/rum-nextjs

  • Added addNextjsError(error, errorInfo?) — a new public API, mirroring addReactError from rum-react, for reporting errors from Next.js App Router error boundaries (error.tsx, global-error.tsx) and from createRoot's onUncaughtError / onRecoverableError hooks
  • Refactored nextjsPlugin to use addError instead of addEvent, aligning with how reactPlugin works
  • Exported addNextjsError from the package entry point

packages/core

  • Added 'nextjs error' as a valid createHandlingStack type

test/apps/nextjs

  • Added App Router test pages: /error-test, /error-test/server-error, /global-error-test, and global-error.tsx to exercise client, server digest, and global error scenarios

test/e2e

  • Added E2E scenarios covering:
    • Client-side error reported via addNextjsError
    • Server error with digest reported via addNextjsError
    • Global error via global-error.tsx
  • Error scenarios scoped to App Router only

Test instructions

You can build the test app:
yarn install && yarn build && yarn build:apps cd test/apps/nextjs/ yarn dev

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

@datadog-prod-us1-6
Copy link
Copy Markdown

datadog-prod-us1-6 bot commented Mar 16, 2026

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 90.91%
Overall Coverage: 77.25% (+0.01%)

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

@BeltranBulbarellaDD BeltranBulbarellaDD marked this pull request as ready for review March 16, 2026 12:34
@BeltranBulbarellaDD BeltranBulbarellaDD requested a review from a team as a code owner March 16, 2026 12:34

await flushEvents()

// React StrictMode double-fires useEffect in dev mode, so we may get 2 errors
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

❓ question: ‏Any reason to use dev mode?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In local we use dev and in the CI we use the prod one. I thought it would cover all cases but we could just do prod. WDYT?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Shouldn’t this double fire also happen with the React plugin? How do we handle it there?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah we do the same "optimistic check" this is what React does:
toBeGreaterThan(0)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Okay so you can keep it like this :)

startClocks,
context: {
...(error as Error & { dd_context?: Context }).dd_context,
...(error.digest && { nextjs: { digest: error.digest } }),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

❓ question: ‏Should nextjs.digest part of the rum-evens-format

@cit-pr-commenter-54b7da
Copy link
Copy Markdown

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

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 175.02 KiB 175.02 KiB 0 B 0.00%
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.80 KiB 56.80 KiB 0 B 0.00%
Flagging 944 B 944 B 0 B 0.00%
Rum Slim 130.66 KiB 130.66 KiB 0 B 0.00%
Worker 23.63 KiB 23.63 KiB 0 B 0.00%
🚀 CPU Performance
Action Name Base CPU Time (ms) Local CPU Time (ms) 𝚫%
RUM - add global context 0.0038 0.0046 +21.05%
RUM - add action 0.0124 0.0129 +4.03%
RUM - add error 0.0126 0.0147 +16.67%
RUM - add timing 0.0025 0.0027 +8.00%
RUM - start view 0.0121 0.0122 +0.83%
RUM - start/stop session replay recording 0.0007 0.0007 0.00%
Logs - log message 0.0138 0.0168 +21.74%
🧠 Memory Performance
Action Name Base Memory Consumption Local Memory Consumption 𝚫
RUM - add global context 27.56 KiB 26.67 KiB -907 B
RUM - add action 51.79 KiB 51.72 KiB -63 B
RUM - add timing 25.59 KiB 26.26 KiB +679 B
RUM - add error 56.29 KiB 54.82 KiB -1.47 KiB
RUM - start/stop session replay recording 25.04 KiB 25.81 KiB +792 B
RUM - start view 461.57 KiB 465.17 KiB +3.60 KiB
Logs - log message 43.71 KiB 43.99 KiB +287 B

🔗 RealWorld


await flushEvents()

// React StrictMode double-fires useEffect in dev mode, so we may get 2 errors
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Okay so you can keep it like this :)

@BeltranBulbarellaDD BeltranBulbarellaDD merged commit d7f24cc into main Mar 17, 2026
21 checks passed
@BeltranBulbarellaDD BeltranBulbarellaDD deleted the beltran.bulbarella/nextjs_app_router_error branch March 17, 2026 12:12
@github-actions github-actions bot locked and limited conversation to collaborators Mar 17, 2026
@ncreated ncreated restored the beltran.bulbarella/nextjs_app_router_error branch April 9, 2026 10:03
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.

3 participants