Skip to content

✨ NextJS Add addNextJSError component#4289

Open
BeltranBulbarellaDD wants to merge 3 commits intomainfrom
beltran.bulbarella/nextjs-addNextjsError
Open

✨ NextJS Add addNextJSError component#4289
BeltranBulbarellaDD wants to merge 3 commits intomainfrom
beltran.bulbarella/nextjs-addNextjsError

Conversation

@BeltranBulbarellaDD
Copy link
Contributor

@BeltranBulbarellaDD BeltranBulbarellaDD commented Mar 6, 2026

Motivation

Discussed in this RFC specifically here

Changes

(AI written)

Add addNextjsError(error, context?) to @datadog/browser-rum-nextjs. This is the integration point for reporting errors caught by Next.js error boundaries (error.tsx / global-error.tsx) to Datadog RUM.

  • addNextjsError — wraps publicApi.addError with:
    • framework: 'nextjs' context.
    • nextjs.digest context when the error has a digest (server component errors) — this hash links client-side errors to server-side logs
  • getGlobalPublicApi() getter added to nextjsPlugin.ts to expose the RUM public API
  • Exported from @datadog/browser-rum-nextjs main entry
  • README updated with usage section for error.tsx and global-error.tsx
  • E2E test app pages added: client error thrower, error boundary with addNextjsError, server component that throws, and global-error.tsx

Test instructions

(AI written)

  1. Unit tests: yarn test:unit --spec packages/rum-nextjs/src/domain/addNextjsError.spec.ts (6 specs)
  2. E2E tests: yarn test:e2e -g "addNextjsError" (2 scenarios — client error + server error with digest)
  3. Note: React StrictMode double-fires useEffect in dev mode, so E2E tests assert >= 1 custom errors rather than exactly 1

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

@BeltranBulbarellaDD
Copy link
Contributor Author

@codex pls review

@datadog-official
Copy link

datadog-official bot commented Mar 6, 2026

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 80.00%
Overall Coverage: 76.77% (+0.00%)

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

@cit-pr-commenter-54b7da
Copy link

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

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 174.43 KiB 174.43 KiB 0 B 0.00%
Rum Profiler 6.16 KiB 6.16 KiB 0 B 0.00%
Rum Recorder 25.24 KiB 25.24 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.11 KiB 130.11 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.0094 0.0044 -53.19%
RUM - add action 0.0489 0.013 -73.42%
RUM - add error 0.0379 0.0129 -65.96%
RUM - add timing 0.0061 0.0029 -52.46%
RUM - start view 0.0217 0.0119 -45.16%
RUM - start/stop session replay recording 0.0012 0.0007 -41.67%
Logs - log message 0.0283 0.014 -50.53%
🧠 Memory Performance
Action Name Base Memory Consumption Local Memory Consumption 𝚫
RUM - add global context 25.95 KiB 26.41 KiB +470 B
RUM - add action 50.84 KiB 51.54 KiB +724 B
RUM - add timing 26.68 KiB 25.58 KiB -1.10 KiB
RUM - add error 56.47 KiB 55.11 KiB -1.35 KiB
RUM - start/stop session replay recording 25.80 KiB 25.01 KiB -816 B
RUM - start view 451.32 KiB 450.90 KiB -436 B
Logs - log message 44.45 KiB 44.34 KiB -108 B

🔗 RealWorld

@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: a6c24fa210

ℹ️ 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 marked this pull request as ready for review March 9, 2026 08:12
@BeltranBulbarellaDD BeltranBulbarellaDD requested review from a team as code owners March 9, 2026 08:12
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: aecc13fe47

ℹ️ 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".

/// <reference types="next" />
/// <reference types="next/image-types/global" />
import "./.next/types/routes.d.ts";
import "./.next/dev/types/routes.d.ts";

Choose a reason for hiding this comment

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

P1 Badge Revert edits to generated next-env declaration

next-env.d.ts is a Next.js-generated file ("NOTE: This file should not be edited"), and /workspace/browser-sdk/AGENTS.md explicitly says generated files must never be manually modified; committing the import change to ./.next/dev/types/routes.d.ts hard-codes a dev-only generated path that gets rewritten by Next and can fail on clean/typecheck builds before .next/dev exists. Please drop this manual edit and let Next regenerate the file.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants