dd-instrument-error-tracking
Installation
SKILL.md
Datadog Browser Error Tracking
Browser Error Tracking groups and triages frontend exceptions collected by the Datadog RUM Browser SDK (@datadog/browser-rum). It shares the same SDK and the same RUM application as Browser RUM and Product Analytics, so there is no separate Error Tracking SDK to install.
How it works
- The switch is on the RUM application, not in the code. A RUM application processes errors when
rum_event_processing_stateisERROR_FOCUSED_MODEorALL. An application created for Product Analytics only starts atNONE, which drops all RUM and Error Tracking events even when the browser code is wired. - RUM comes first. Browser Error Tracking reads what the RUM Browser SDK sends, so an app with no RUM init needs RUM set up first.
- Sampling uses
sessionSampleRate. The RUM Browser SDK captures unhandled errors (window.onerror,unhandledrejection,console.error) automatically for sampled sessions. There is noerrorSampleRateoption inRumInitConfiguration; adding it breaks TypeScript builds. - Frameworks swallow component errors. React error boundaries, Next.js
error.tsx, Vueapp.config.errorHandler, AngularErrorHandler, and SvelteKithandleErrorintercept errors before they reachwindow.onerror, so those hooks must forward caught errors to Datadog. - Credentials. The application ID and client token are public and already in the RUM setup. Switching event processing on through the API needs an API key and an application key, and both are secret.
Set up
Copy these steps into your reply and tick them off as you go.
- Inspect. Find the browser app; in a monorepo with several, ask which one. Search source and HTML files, skipping
node_modulesand build output, for the RUM setup: aninitcall on thedatadogRumimport from@datadog/browser-rum, including renamed imports and wrapper modules, or a CDNDD_RUM.init. Record the number of inits, the framework,sessionSampleRate, thesite(absent meansdatadoghq.com), the application ID, any@datadog/browser-rum-*or@datadog/browser-logspackages, and any existing error boundary or framework error handler. When the init reads the application ID or the site from environment variables, read only those lines of the env file, for examplegrep -E '^VITE_DD_(RUM_APPLICATION_ID|SITE)=' .env.local, because env files often hold secrets.