Skip to content

⚗️ Add Nuxt plugin with router tracking#4424

Merged
BeltranBulbarellaDD merged 18 commits intomainfrom
beltran.bulbarella/nuxt_router
Apr 13, 2026
Merged

⚗️ Add Nuxt plugin with router tracking#4424
BeltranBulbarellaDD merged 18 commits intomainfrom
beltran.bulbarella/nuxt_router

Conversation

@BeltranBulbarellaDD
Copy link
Copy Markdown
Contributor

@BeltranBulbarellaDD BeltranBulbarellaDD commented Mar 31, 2026

Motivation

Add a first-party Nuxt integration for Browser RUM so Nuxt applications can plug into Datadog RUM with Nuxt-aware view tracking. This also gives us stable view names for Nuxt router templates instead of grouping views by concrete URLs.

Changes

  • Add a new @datadog/browser-rum-nuxt package with a nuxtRumPlugin(router) helper.
  • Configure the plugin to use manual view tracking and start RUM views from Nuxt router navigations.
  • Normalize Nuxt dynamic and catch-all routes into stable view names such as /user/[id] and /guides/[...slug].
  • Avoid creating extra views for failed navigations or same-path navigations that only change query params or hashes.
  • Add unit coverage for the Nuxt plugin and router view-name/tracking behavior.
  • Add a dedicated Nuxt test app plus Playwright coverage, and wire the Nuxt app into the E2E/build harness

Test instructions

  • yarn test:unit --spec packages/rum-nuxt/src/domain/nuxtPlugin.spec.ts
  • yarn test:unit --spec packages/rum-nuxt/src/domain/router/nuxtRouter.spec.ts
  • yarn build:apps --app nuxt-app
  • yarn test:e2e -g "nuxt - router"

Also can go into the nuxt test app package and use the developer extension to see events manually.

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

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

cit-pr-commenter-54b7da Bot commented Mar 31, 2026

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 177.94 KiB 177.94 KiB 0 B 0.00%
Rum Profiler 6.16 KiB 6.16 KiB 0 B 0.00%
Rum Recorder 27.03 KiB 27.03 KiB 0 B 0.00%
Logs 56.40 KiB 56.40 KiB 0 B 0.00%
Rum Slim 133.81 KiB 133.81 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.0045 0.0057 +26.67%
RUM - add action 0.0143 0.0155 +8.39%
RUM - add error 0.0134 0.0164 +22.39%
RUM - add timing 0.0032 0.0037 +15.63%
RUM - start view 0.0142 0.0178 +25.35%
RUM - start/stop session replay recording 0.0007 0.001 +42.86%
Logs - log message 0.0142 0.02 +40.85%
🧠 Memory Performance
Action Name Base Memory Consumption Local Memory Consumption 𝚫
RUM - add global context 27.50 KiB 27.51 KiB +14 B
RUM - add action 96.72 KiB 104.35 KiB +7.63 KiB
RUM - add timing 26.30 KiB 25.80 KiB -505 B
RUM - add error 97.86 KiB 103.85 KiB +5.99 KiB
RUM - start/stop session replay recording 26.29 KiB 25.96 KiB -342 B
RUM - start view 484.58 KiB 484.39 KiB -199 B
Logs - log message 102.30 KiB 100.91 KiB -1.38 KiB

🔗 RealWorld

@datadog-official
Copy link
Copy Markdown

datadog-official Bot commented Mar 31, 2026

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 72.09%
Overall Coverage: 77.58% (-0.03%)

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

@BeltranBulbarellaDD
Copy link
Copy Markdown
Contributor Author

@codex pls review

Copy link
Copy Markdown

@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: 0a30fc683c

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

Comment thread packages/rum-nuxt/package.json
Comment thread packages/rum-nuxt/src/domain/nuxtPlugin.ts Outdated
@BeltranBulbarellaDD
Copy link
Copy Markdown
Contributor Author

@codex pls review

Copy link
Copy Markdown

@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: 86e5acfaf2

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

Comment thread packages/rum-nuxt/package.json
Comment thread packages/rum-nuxt/src/domain/nuxtPlugin.ts Outdated
@BeltranBulbarellaDD
Copy link
Copy Markdown
Contributor Author

@codex pls review

Copy link
Copy Markdown

@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: 3416d19292

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

Comment thread packages/rum-nuxt/package.json
@BeltranBulbarellaDD BeltranBulbarellaDD marked this pull request as ready for review April 2, 2026 14:53
@BeltranBulbarellaDD BeltranBulbarellaDD requested a review from a team as a code owner April 2, 2026 14:53
@BeltranBulbarellaDD BeltranBulbarellaDD changed the title Add Nuxt plugin with router tracking ⚗️ Add Nuxt plugin with router tracking Apr 2, 2026
Copy link
Copy Markdown
Contributor

@mormubis mormubis left a comment

Choose a reason for hiding this comment

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

LGTM

rumPublicApi.startView(computeNuxtViewName(router.currentRoute.value.matched))
}

router.afterEach((to, from, failure) => {
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: ‏We hook at the same place as Vue, but computeNuxtViewName differs, why?

Copy link
Copy Markdown
Contributor Author

@BeltranBulbarellaDD BeltranBulbarellaDD Apr 9, 2026

Choose a reason for hiding this comment

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

The view name computation differs intentionally because Nuxt’s public route model is file based, while the Vue integration exposes raw Vue Router path syntax.

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.

Like we discussed, can you explain why you use afterEach instead of Nuxt hooks https://nuxt.com/docs/4.x/api/advanced/hooks#app-hooks-runtime

Copy link
Copy Markdown
Contributor Author

@BeltranBulbarellaDD BeltranBulbarellaDD Apr 9, 2026

Choose a reason for hiding this comment

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

Yeah! So page:loading:start is not the right replacement for view tracking because it fires before route resolution and provides no to route or matched records, so we can’t compute the correct Nuxt view name from it. It would also mishandle aborted or redirected navigations, since the hook can fire even when the final resolved route differs from the navigation that started. Nuxt also documents that it may fire on page key changes or when a page is reused without setup() rerunning, so it can produce extra view starts that don’t match actual route changes. (Link)

const raw = Array.isArray(rumConfigParam) ? rumConfigParam[0] : rumConfigParam
if (raw) {
const config = JSON.parse(raw)
datadogRum.init({ ...config, plugins: [nuxtRumPlugin(useRouter())] })
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: ‏Why calling useRouter() from here and not within nuxtRumPlugin?

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.

Because Nuxt handles the creation of the router and it can be the Vue router or a Universal One (Link) So we pass it down to use the one Nuxt creates.

@BeltranBulbarellaDD BeltranBulbarellaDD merged commit 218ba7b into main Apr 13, 2026
22 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 13, 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.

3 participants