dd-instrument-error-tracking
Skill185 starsChanged 38 days agoMITView on GitHub
Sets up Datadog Browser Error Tracking for a web app that runs the Datadog RUM Browser SDK. Turns error processing on for the app's RUM application, forwards framework-caught errors (React, Next.js, Vue, Angular, SvelteKit) to Datadog, and checks that events arrive. Use when asked to add, set up, enable or verify Error Tracking or frontend exception tracking in a browser app. Not for adding RUM itself, which dd-instrument-rum does first, or for uploading source maps, which dd-browser-sdk does.
- Reads credentials
In this repository43 other files it gives its agents.
- dd-account-setupSkill
- dd-agent-install-dockerSkill
- dd-agent-install-kubernetesSkill
- dd-agent-install-linuxSkill
- dd-agent-install-macosSkill
- dd-agent-install-windowsSkill
- dd-android-sdkSkill
- dd-anthropic-usage-and-costs-onboardingSkill
- dd-apmSkill
- dd-auditSkill
- dd-aws-ccmSkill
- dd-aws-integrationSkill
- dd-aws-log-forwardingSkill
- dd-aws-storage-managementSkill
- dd-azure-ccmSkill
- dd-azure-integrationSkill
- dd-azure-log-forwardingSkill
- dd-browser-sdkSkill
- dd-confluent-cloud-integrationSkill
- dd-dbm-rds-postgresSkill
- dd-docsSkill
- dd-gcp-ccmSkill
- dd-gcp-integrationSkill
- dd-gcp-log-forwardingSkill
- dd-github-copilot-onboardingSkill
- dd-github-costs-onboardingSkill
- dd-github-onboardingSkill
- dd-instrument-llmoSkill
- dd-instrument-product-analyticsSkill
- dd-instrument-rumSkill
- dd-instrument-test-optimizationSkill
- dd-logsSkill
- dd-monitorsSkill
- dd-nebius-integrationSkill
- dd-oci-ccmSkill
- dd-oci-integrationSkill
- dd-openai-onboardingSkill
- dd-orchestratorSkill
- dd-pagerduty-onboardingSkill
- dd-product-recommenderSkill
- dd-profiler-setupSkill
- dd-pupSkill
- dd-slack-integrationSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 2 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 33
Two or more inits, or npm and CDN setups mixed: stop and report each location, because a second init splits sessions and errors between …
- Distinctive: line 34
No application ID found: ask the user. It is listed under Real User Monitoring > Manage Applications in Datadog.
- Very specific: line 39
If the existing datadogRum.init sets sessionSampleRate: 0, no sessions are sampled and no errors are sent.
- Very specific: line 40
If @datadog/browser-logs is already installed and datadogLogs.init is present without forwardErrorsToLogs, add forwardErrorsToLogs: true.
- Very specific: line 41
Leave the credentials, site, service, and unrelated options in datadogRum.init unchanged.
≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
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. - Check what Error Tracking needs.
- No browser app, for example a backend service or a mobile app: stop before any edit and report that this skill covers browser apps only. Do not offer Browser RUM, because it cannot collect errors from that project.
- No RUM init: stop before any edit. Tell the user that Browser Error Tracking collects its data through the RUM Browser SDK, that this app has none, and that RUM must be set up first with the
dd-instrument-rumskill. Ask whether to set up RUM now. On yes, run that skill; when it is not installed, get it from that link or follow the Browser Monitoring setup docs. Then restart at step 1, and if there is still no init with an application ID, stop and report it. On no, or when you cannot ask, end without changes and report that RUM is missing. - Two or more inits, or npm and CDN setups mixed: stop and report each location, because a second init splits sessions and errors between configurations. Repairing that belongs to RUM setup.
- No application ID found: ask the user. It is listed under Real User Monitoring > Manage Applications in Datadog.
- Turn Error Tracking processing on. Check for both keys without printing them:
[ -n "$DD_API_KEY" ] && [ -n "$DD_APP_KEY" ] && echo set. With keys, follow references/api-switch.md: it reads the current state, leavesALLorERROR_FOCUSED_MODEuntouched, and sendsrum_event_processing_state: ERROR_FOCUSED_MODEonly when the current state isNONE. Without keys, or after a failure, give the user the settings step: in Datadog, open Digital Experience > Real User Monitoring > Manage Applications, select the application, and under Application Settings enable Error Tracking event processing. BuildAPP_HOSTas described in Verify and view. When the Datadog MCP server has the RUM toolset,Datadog:search_rum_applicationsreportsrum_event_processing_state, which confirms either path. - Check session sampling and Logs forwarding.
- If the existing
datadogRum.initsetssessionSampleRate: 0, no sessions are sampled and no errors are sent; ask before changing it to100. WhensessionSampleRateis absent, leave it alone (it defaults to100). Never adderrorSampleRate. - If
@datadog/browser-logsis already installed anddatadogLogs.initis present withoutforwardErrorsToLogs, addforwardErrorsToLogs: true. Do not install@datadog/browser-logsfrom scratch, because Browser Logs is a separate product with its own setup. - Leave the credentials, site, service, and unrelated options in
datadogRum.initunchanged.
- If the existing
- Forward framework-caught errors. Open references/framework-errors.md and wire the error hook for the detected framework (React, Next.js, Vue, Nuxt, Angular, or SvelteKit) so errors caught by the framework are reported to Datadog without replacing existing UI or reporting the same error twice. Plain JavaScript, plain Svelte, and CDN apps need no framework hook.
- Build and run. Run the project's build, fix errors your edits caused, and run it again until it passes. Then start the app with its dev command, load a page, keep the page open for about 30 seconds, and stop the server. The SDK sends its batch every 30 seconds or when the page is hidden.
Verify and view
Record the highest level you actually reached:
- Configuration changed: the switch result from step 3 and the code edits are in place.
- The app ran: the project built cleanly and a page loaded in a browser.
- Export accepted: a request to a
browser-intake-…host, or to the init'sproxyURL, with path/api/v2/rum, returned 202. Check in a headless browser when one is available, or ask the user to look in DevTools > Network. - Datadog shows events:
Datadog:search_datadog_rum_events, or the Search RUM events endpoint with the same keys, finds@application.id:<APP_ID> @session.initial_view.url_host:localhostin the last 15 minutes. A new application can take a few minutes to show data, so query once a minute for up to 10 minutes; if nothing arrives, stop at level 3 and give the link.
A passing build shows only that the project compiles. Name each level you could not check and the step left for the user.
The app host is app.datadoghq.com for datadoghq.com, app.datadoghq.eu for datadoghq.eu, app.ddog-gov.com for ddog-gov.com, and the site itself for the others, for example us5.datadoghq.com. End with this summary:
Error Tracking: turned on | already on | waiting for your settings step (<the step>)
Changed: <files, or none>
Evidence: <highest level reached>; not checked: <levels and the step left>
View: https://APP_HOST/error-tracking?query=@application.id:<APP_ID>Undo
Revert this run's code edits (framework error hook or boundary). If this run changed rum_event_processing_state from NONE to ERROR_FOCUSED_MODE, follow the undo note in references/api-switch.md. Leave the RUM setup as it is.
Gotchas
| Mistake | Symptom | Fix |
Sending rum_event_processing_state: ERROR_FOCUSED_MODE when the app is at ALL | Downgrades full RUM and drops non-error sessions | Read the state first; update only when it is NONE |
Sending product_analytics_retention_state: NONE in the update | Turns Product Analytics off for the app | Omit product_analytics_retention_state from the PATCH body |
Adding errorSampleRate to datadogRum.init | TypeScript build fails (errorSampleRate is not a valid option) | Use sessionSampleRate (defaults to 100) |
Calling datadogRum.addError in server-only Next.js or SvelteKit code | Server error is never sent by the browser SDK | Call it in a client error boundary ('use client') or hooks.client |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

