Datadog UX Utils is a toolkit that helps you measure and improve user experience in web apps. It works with Datadog RUM and Logs, and provides simple tools for tracking performance, errors, and user flows.
Install the package and its Datadog dependencies:
npm install datadog-ux-utils @datadog/browser-rum @datadog/browser-logs
If you use React, make sure you have react
and react-dom
installed.
Initialize Datadog and start tracking:
import { initDatadogUx, startFlow } from "datadog-ux-utils";
initDatadogUx({ appName: "MyApp" });
const flow = startFlow("checkout");
// ...when done
flow.end();
React error boundary:
import {
ErrorBoundary,
RenderProfiler,
SuspenseWatch,
} from "datadog-ux-utils/react";
<ErrorBoundary name="AppRoot" fallback={<h1>Something broke.</h1>}>
<App />
</ErrorBoundary>;
You can also combine React helpers:
import {
ErrorBoundary,
RenderProfiler,
SuspenseWatch,
} from "datadog-ux-utils/react";
<ErrorBoundary name="AppRoot" fallback={<h1>Something broke.</h1>}>
<RenderProfiler id="MainShell">
<SuspenseWatch
id="MainData"
fallback={<Spinner />}
options={{ timeoutMs: 120 }}
>
<App />
</SuspenseWatch>
</RenderProfiler>
</ErrorBoundary>;
Import only what you need (tree-shake friendly):
api
, perf
, react
, env
, errors
, telemetry
, ux
Example:
import { ddFetch } from "datadog-ux-utils/api";
import { registerWebVitals } from "datadog-ux-utils/perf";
import { ErrorBoundary } from "datadog-ux-utils/react";
import { networkInfo } from "datadog-ux-utils/env";
import { captureConsole } from "datadog-ux-utils/errors";
import { enqueueOffline } from "datadog-ux-utils/telemetry";
import { startFlow } from "datadog-ux-utils/ux";
import { useComponentTelemetry } from "datadog-ux-utils/react";
export function Button(
props: { variant?: string } & React.ButtonHTMLAttributes<HTMLButtonElement>
) {
useComponentTelemetry("Button", { variant: props.variant });
return <button {...props} />;
}
Custom sink example (send batch to your own endpoint instead of individual addAction
calls):
initComponentTelemetry({
sampleRate: 0.5,
sink(batch) {
navigator.sendBeacon("/_telemetry/components", JSON.stringify(batch));
},
});
Impact Score | Utility/Components |
---|---|
1 (Least) | ErrorBoundary.tsx |
2 | circuitBreaker.ts, dedupe.ts, rateGuard.ts, retry.ts, responseSize.ts, RenderProfiler.tsx, suspenseWatch.tsx, useGuardFetch.ts, useGuardedCall.ts, flowTimer.ts, routeTiming.ts, RenderDetector.tsx, consoleCapture.ts, resourceErrors.ts, offlineQueue.ts, offlineQueue.persistent.ts, network.ts |
3 | ddFetch.ts |
4 | idle.ts, layoutShifts.ts, longTasks.ts, memory.ts, memoryPeak.ts, resources.ts |
5 (Most) | webVitals.ts |
Impact is an approximate relative cost bucket when enabled with default options (1 = minimal overhead, 5 = highest). Most utilities are event / observer driven and noop when corresponding config flags are disabled.
Browse TypeDoc output in the repo:
ddFetch
, registerWebVitals
, startLongTaskObserver
To regenerate locally:
npm run docs
To watch & rebuild while iterating:
npm run docs:serve
npm install
npm run build # emits ESM + CJS into dist/
npm test # Vitest unit tests
npm run test:coverage # Coverage report
npm run size # Enforce bundle size limits (size-limit)
Individual tree‑shaken scenarios (see size-limit/*
) include telemetry-only usage:
size-limit --why --limit 2 KB size-limit/only-componentTelemetry.js
prepublishOnly
runs typecheck, tests, build, and docs to ensure published artifacts are consistent.
Automated releases use semantic-release (Angular commit convention) once NPM_TOKEN
is configured.
Use initDatadogUx
(see config.ts
) to set:
appName
– identifier included on actions/errorsactionSampleRate
, apiSlowMs
, renderSlowMs
, apiLargeKb
, captureWebVitals
, captureLongTasks
, etc.See generated docs for all config fields: getUxConfig
and initDatadogUx
.
npm install
npm run typecheck && npm test
Please see CONTRIBUTING.md
for full guidelines.
MIT – see LICENSE
.
createRoot
).localStorage
).Import and use the utilities as needed in your application. See individual files for API documentation and usage examples.
MIT