[DRAFT] ⚗️ Add soft navigation tracking (experimental)#4154
Open
[DRAFT] ⚗️ Add soft navigation tracking (experimental)#4154
Conversation
|
I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
5f97f80 to
8f02dac
Compare
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🔗 Commit SHA: a8b399d | Docs | Datadog PR Page | Was this helpful? Give us feedback! |
8f02dac to
9f3daa1
Compare
Bundles Sizes Evolution
🚀 CPU PerformancePending... 🧠 Memory PerformancePending... |
Add experimental soft navigation tracking behind a feature flag. Listens for soft-navigation performance entries and correlates them with RUM view events via is_soft_navigation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
9f3daa1 to
7f32214
Compare
… window The soft-navigation PerformanceEntry's startTime is emitted ~1ms after the view's startClocks.relative because the SDK detects the URL change (via history.pushState override) slightly before Chrome finalizes the entry. Using findSoftNavigationByTime (which requires entry.startTime <= queryTime) always failed. Switch to findAll with a 5ms tolerance window to account for this timing offset. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Next.js/Turbopack has a ~17ms gap between SDK view creation and Chrome's soft-navigation PerformanceEntry, exceeding the original 5ms tolerance. Tested and verified across all 4 SPAs (Vue, Angular, Svelte, Next.js). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Single-page applications (SPAs) use client-side routing that doesn't trigger traditional page loads. The browser's Soft Navigation API (currently Chromium-only) detects these user-initiated navigations by observing URL changes paired with DOM modifications triggered by user interaction.
This PR adds experimental support for correlating the browser's soft navigation entries with RUM view events, enabling Datadog to distinguish user-initiated route changes from programmatic ones via a new
view.is_soft_navigationboolean field.Changes
All changes are gated behind the
soft_navigationexperimental feature flag — when disabled, the feature is a complete no-op with zero runtime cost.Types & Schema (
packages/rum-core/src/rawRumEvent.types.ts,packages/rum-core/src/browser/performanceObservable.ts)is_soft_navigationboolean toRawRumViewEvent.viewSOFT_NAVIGATIONperformance entry type andRumSoftNavigationEntryinterfaceConfiguration & Feature Detection (
packages/core/src/tools/experimentalFeatures.ts,packages/core/src/domain/telemetry/telemetryEvent.types.ts,packages/rum-core/src/domain/configuration/)ExperimentalFeature.SOFT_NAVIGATIONenum valueuse_soft_navigationinto configuration telemetry serializationSoft Navigation Collection (
packages/rum-core/src/domain/softNavigation/softNavigationCollection.ts)startSoftNavigationCollectionmodule that observessoft-navigationPerformanceEntry events viaPerformanceObserverValueHistoryof soft navigation contexts for time-based lookupsView Correlation (
packages/rum-core/src/domain/view/viewCollection.ts,packages/rum-core/src/boot/startRum.ts)softNavigationContextsintostartViewCollectionandprocessViewUpdateroute_changeviews, usesfindAllwith a 50ms tolerance window to check if a soft navigation entry overlaps the view's start time, settingis_soft_navigation: truehistory.pushStateoverride) and Chrome finalizing thesoft-navigationPerformanceEntry (~1ms on Vite, ~17ms on Turbopack/Next.js)All changes in this PR were AI-agent generated.
SPA Integration Test Results
Tested with a monorepo of 4 SPA frameworks, each instrumented with the built SDK from this branch (
enableExperimentalFeatures: ['soft_navigation']). Chromechrome://flags/#soft-navigation-heuristicsenabled.is_soft_navigationtruetruetruetrueKey findings:
history.pushState()+ DOM mutation in the same user-interaction task. Standard SPA router navigations update DOM asynchronously via their reactivity systems and do not producesoft-navigationPerformanceEntries — only directpushState+ DOM mutation in a click handler does.findSoftNavigationByTime(exact match) which failed due to this timing offset. Changed tofindAllwith a tolerance window to handle the gap.Test instructions
Unit tests
E2E tests (requires Chromium with soft-navigation flag)
yarn test:e2e -g "soft navigation"The E2E tests cover three scenarios:
is_soft_navigation: trueis_soft_navigationis undefinedChecklist
🤖 Generated with Claude Code