Skip to content

[RUM] React Profiler#4505

Draft
MandragoreVR wants to merge 2 commits intomainfrom
teo.chaillou/react-sdk-profiling
Draft

[RUM] React Profiler#4505
MandragoreVR wants to merge 2 commits intomainfrom
teo.chaillou/react-sdk-profiling

Conversation

@MandragoreVR
Copy link
Copy Markdown
Collaborator

@MandragoreVR MandragoreVR commented Apr 20, 2026

Motivation

This PR is an attempt made by Claude to have a working React Profiler. This is part of the initiative for the Agentic Week (detailed here).

Changes

Generated by Claude

Schema & type generation (rum-events-format, scripts/)

  • Point rum-events-format submodule to teo.chaillou/RUM-react-profiling branch, which adds React profiling JSON
    schemas (react-profiling-browser-schema.json, react-profile-trace-schema.json, _common-schema.json)
  • Register the two new schemas in scripts/lib/generatedSchemaTypes.ts so yarn json-schemas:generate produces
    packages/rum-react/src/types/reactProfiling.ts and packages/rum-react/src/types/reactProfileTrace.ts

Plugin API surface (packages/rum-core)

  • Extend OnRumStartOptions in plugins.ts with profilingEndpointBuilder, configuration, lifeCycle,
    session, viewHistory, and createEncoder so plugins can access profiling infrastructure
  • Pass those new fields from rumPublicApi.ts when calling callPluginsMethod('onRumStart', ...)
  • Add DeflateEncoderStreamId.REACT_PROFILING = 7 in packages/core
  • (unrelated, pre-existing) trackCommonViewMetrics.ts and rumPublicApi.ts contain setViewLoadingTime
    telemetry changes

React profiler core (packages/rum-react)

  • createReactProfiler.ts (new, 282 lines): Windowed profiling controller that batches component renders into
    samples, rotates windows on a configurable interval or visibility change, and sends FormData payloads (event.json
  • react-profiling.json) to /api/v2/profile via createFormDataTransport
  • reactPlugin.ts: On onRumStart, creates and starts the profiler when the session is sampled at
    profilingSampleRate. Exposes isReactProfilingRunning() and getRunningReactProfiler() for use by the
    <ReactProfiler> component
  • reactProfiler.tsx (new, 164 lines): <ReactProfiler name="..."> component using a dual strategy —
    <React.Profiler> for base_duration + sentinel LifeCycle components for per-phase durations (render,
    layoutEffect, effect)
  • collectReactComponentRender.ts (new): Bridge that forwards render data from the <ReactProfiler> component
    to the running profiler's addComponentRender
  • timer.ts, performance/index.ts: Timer utility for phase measurement; re-export ReactProfiler
  • entries/main.ts: Export ReactProfiler and ReactProfilerContext from the package public API
  • reactProfiler.spec.tsx (new, 433 lines): Unit tests for the <ReactProfiler> component

Test app (test/apps/react-shopist-like)

  • Add @datadog/browser-rum and @datadog/browser-rum-react dependencies with tarball resolutions
  • Initialize the RUM SDK with profilingSampleRate: 100 and the React plugin in main.tsx
  • Wrap <ProductCard> with <ReactProfiler name="ProductCard">

Test helpers (packages/rum-react/test)

  • Extend initializeReactPlugin to accept lifeCycle, sessionManager, viewHistory, createEncoder, and
    rumConfiguration for profiling-related tests

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

datadog-datadog-prod-us1 Bot commented Apr 20, 2026

Tests

Fix all issues with BitsAI or with Cursor

⚠️ Warnings

🧪 5 Tests failed

ReactProfiler deduplication should emit only one render per ReactProfiler per commit from Chrome Headless 146.0.0.0 (Linux 0.0.0)   View in Datadog   (Fix with Cursor)
Error: Expected 2 to be 1.
    at <Jasmine>
    at UserContext.<anonymous> (/go/src/github.com/DataDog/browser-sdk/packages/rum-react/src/domain/performance/reactProfiler.spec.tsx:381:53 <- /tmp/_karma_webpack_186951/commons.js:414439:59)
ReactProfiler profiling build mode (React.Profiler fires) should report update phase on re-render from Chrome Headless 146.0.0.0 (Linux 0.0.0)   View in Datadog   (Fix with Cursor)
TypeError: Cannot read properties of undefined (reading 'renders')
    at UserContext.<anonymous> (/go/src/github.com/DataDog/browser-sdk/packages/rum-react/src/domain/performance/reactProfiler.spec.tsx:198:25 <- /tmp/_karma_webpack_186951/commons.js:414327:31)
ReactProfiler sample batching should group renders from the same React commit into one sample from Chrome Headless 146.0.0.0 (Linux 0.0.0)   View in Datadog   (Fix with Cursor)
Error: Expected 4 to be 2.
    at <Jasmine>
    at UserContext.<anonymous> (/go/src/github.com/DataDog/browser-sdk/packages/rum-react/src/domain/performance/reactProfiler.spec.tsx:334:41 <- /tmp/_karma_webpack_186951/commons.js:414409:47)
View all

ℹ️ Info

No other issues found (see more)

❄️ No new flaky tests detected

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: ab8c298 | Docs | Datadog PR Page | Give us feedback!

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.

1 participant